ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
int i = 0;
while (i++ < 5);
printf("%d", i);
  1. A. 6
  2. B. Nothing: it loops forever
  3. C. 4
  4. D. 5

Correct answer: A. 6

The semicolon is an empty loop body. The test compares the old value and then increments: it succeeds for 0 to 4, and the failing test (5 < 5) still increments i to 6.

More C Programming questions

Exams that ask this topic