ProgrammingHardWipro · Cognizant pattern

What is printed?

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

Correct answer: D. 3 7

The comma operator lets the for-loop init and update run two statements each. i runs 0,1,2 and the loop body (empty) executes 3 times, stopping when i becomes 3; j, decremented once per iteration, goes from 10 down to 7.

More C Programming questions

Exams that ask this topic