ProgrammingHardProduct company OA

What is printed?

What is printed?
int i = 0, n = 0;
while (i++, i < 4) n += i;
printf("%d %d", n, i);
  1. A. 3 4
  2. B. 6 4
  3. C. 6 3
  4. D. 10 4

Correct answer: B. 6 4

The condition is a comma expression: i is incremented, then i < 4 is the value tested. The body therefore sees i = 1, 2, 3 (n = 6), and the test with i = 4 fails.

More C Programming questions

Exams that ask this topic