ProgrammingHardWipro · Cognizant pattern

What is printed?

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

Correct answer: B. 5 1

Assignment `(a = 5)` has lower precedence than ==, but the parentheses force it to be evaluated as a complete assignment expression first, yielding the value 5 and setting a=5; `5 == 5` is then true (1). a=5, b=1.

More C Programming questions

Exams that ask this topic