ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
int x = 6;
printf("%d %d", x & 2 == 2, (x & 2) == 2);
  1. A. 0 1
  2. B. 1 1
  3. C. 2 1
  4. D. 0 0

Correct answer: A. 0 1

== has higher precedence than &, so x & 2 == 2 means x & (2 == 2) = 6 & 1 = 0. With parentheses, 6 & 2 = 2 and 2 == 2 is 1. Always bracket bitwise tests.

More C Programming questions

Exams that ask this topic