ProgrammingVery hardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int a = 2, b = 3;
    printf("%d", a ^ b == 1);
}
  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 3

Correct answer: C. 2

== binds tighter than ^, so the expression is a ^ (b == 1) = 2 ^ 0 = 2. Reading it as (a ^ b) == 1 gives 1, the tempting wrong answer.

More C Programming questions

Exams that ask this topic