ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

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

Correct answer: B. B0

x = 0 is an assignment, not a comparison: it stores 0 in x and its value, 0, is false. So the else branch runs and prints B with the new x, 0.

More C Programming questions

Exams that ask this topic