ProgrammingModerate

int n = 0; do { n += 2; } while (n < 7); printf("%d", n); What is printed?

  1. A. 6
  2. B. 4
  3. C. 2
  4. D. 8

Correct answer: D. 8

The body runs before each test: n = 2, 4, 6, then 6 < 7 still holds so one more pass gives 8, and 8 < 7 ends the loop. 6 stops one pass early, 4 is the number of iterations, and 2 assumes a do-while body runs only once.

More C Programming questions

Exams that ask this topic