ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
int i = 0, s = 0;
top:
    s += i;
    if (++i < 5) goto top;
printf("%d %d", s, i);
  1. A. 15 5
  2. B. 6 4
  3. C. 10 4
  4. D. 10 5

Correct answer: D. 10 5

The goto builds a loop that adds i = 0, 1, 2, 3, 4 (total 10). ++i reaches 5 on the last test, which fails, so i ends at 5. '15' wrongly adds 5 as well.

More C Programming questions

Exams that ask this topic