Question 8
Back to Exercise
The program should print the area of a square with side 5. What does it print, and why?
#include <stdio.h>
int main(void) {
int side = 5;
int area = side ^ 2;
printf("%d\n", area);
return 0;
}
- A 25 – ^ means power
- B 7 – ^ is bitwise XOR, not exponentiation: 101 ^ 010 = 111 Correct
- C 10 – ^ means multiply
- D It does not compile
Correct Answer: Option B
C has no power operator. ^ is XOR: 5 (101) XOR 2 (010) = 7 (111). Write side * side, or pow() from <math.h> for floating-point powers.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!