ProgrammingHardAccenture · Product company OA

What is printed?

What is printed?
int i, c = 0;
for (i = 0; i < 10; i += i + 1) c++;
printf("%d %d", c, i);
  1. A. 4 15
  2. B. 3 15
  3. C. 5 15
  4. D. 4 7

Correct answer: A. 4 15

The update makes i = 2i + 1: 0, 1, 3, 7 run the body (4 passes), then i becomes 15 and the test fails. '4 7' reports the last value used inside the loop, not the final value.

More C Programming questions

Exams that ask this topic