Question 4
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int x = 4;
if (x & 1 == 0)
puts("even");
else
puts("odd?!");
return 0;
}
- A even
- B odd?! Correct
- C Compilation error
- D Nothing
Correct Answer: Option B
1 == 0 is evaluated first (0), then x & 0 is 0, so the condition is false even though 4 is even. Compilers warn about it. Write (x & 1) == 0.
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!