ProgrammingHard

int i = 0; for (; i < 5; ) i += 2; printf("%d", i); What is printed?

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

Correct answer: A. 6

i goes 0, 2, 4, 6 and the test 6 < 5 fails, so i overshoots the bound and 6 is printed. 4 is the last value that passed the test, 3 is the number of iterations, and 10 assumes the loop runs five times.

More C Programming questions

Exams that ask this topic