ProgrammingHardAccenture · Product company OA

What is printed?

What is printed?
int i = 0, s = 0;
do {
    if (++i == 3) continue;
    if (i == 5) break;
    s += i;
} while (i < 10);
printf("%d %d", s, i);
  1. A. 7 5
  2. B. 15 10
  3. C. 10 5
  4. D. 7 4

Correct answer: A. 7 5

i = 1 and 2 are added (s = 3). At i = 3, continue jumps to the while test, which passes, so nothing is added. i = 4 is added (s = 7), and at i = 5 the loop breaks before adding.

More C Programming questions

Exams that ask this topic