ProgrammingModerate

int i = 1; int s = 0; while (i <= 4) s += i++; printf("%d", s); What is printed?

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

Correct answer: C. 10

The loop adds 1, 2, 3 and 4 before i reaches 5, so the sum is 10.

More C Programming questions

Exams that ask this topic