ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
int x = 4;
if (x & 1 == 0) printf("even");
else printf("odd");
  1. A. Compilation error
  2. B. Nothing
  3. C. even
  4. D. odd

Correct answer: D. odd

== has higher precedence than &, so the test is x & (1 == 0) = 4 & 0 = 0, which is false, and the even number 4 is reported as odd. Write (x & 1) == 0.

More C Programming questions

Exams that ask this topic