ProgrammingHardWipro · Cognizant pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int x = 1;
int y = 2;
int z = 3;
int result = x + y == z;
printf("%d", result);
  1. A. Compile-time error: + and == cannot appear in the same expression without parentheses
  2. B. 0
  3. C. 1
  4. D. 6

Correct answer: C. 1

+ has higher precedence than ==, so x + y == z parses as (x + y) == z, i.e. (1+2) == 3, i.e. 3 == 3, which is true, giving result = 1 (not the sum 6, and not treating '==' as binding first).

More C Programming questions

Exams that ask this topic