ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
int i = 10, c = 0;
do {
    c++;
    i++;
} while (i < 5);
printf("%d %d", i, c);
  1. A. 10 0
  2. B. 11 0
  3. C. 11 1
  4. D. 6 1

Correct answer: C. 11 1

A do-while checks its condition after the body, so the body runs once even though 10 < 5 is false from the start. A while loop with the same condition would not run at all.

More C Programming questions

Exams that ask this topic