ProgrammingHardTCS NQT · Product company OA

What is printed?

What is printed?
int x = 9, y = 0;
if (x = y == 0) printf("A%d", x);
else printf("B%d", x);
  1. A. B0
  2. B. A9
  3. C. A1
  4. D. A0

Correct answer: C. A1

== binds tighter than =, so this is x = (y == 0). y == 0 is 1, so x becomes 1 and the condition is true: A1. Writing (x = y) == 0 would give A0.

More C Programming questions

Exams that ask this topic