ProgrammingHard

int c = 0, n = 3; do { c++; } while (n-- > 0); printf("%d", c); What is printed?

  1. A. 3
  2. B. 2
  3. C. 4
  4. D. 5

Correct answer: C. 4

The body runs first, and the test n-- > 0 is true for n = 3, 2 and 1. It is false when n is 0, so the body has run four times.

More C Programming questions

Exams that ask this topic