Multiple choice

What will be the output of the following function?

include <stdio.h>

void main() { int i =2,j=2; printf(“%d %d %d %d”,i,i++,j,++j); }

  1. 3 3 3 3

  2. 3 2 3 3

  3. 2 2 2 3

  4. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In many C compilers, printf arguments are evaluated from right to left. Starting from the right, ++j makes j=3, then j is 3, then i++ returns 2 (and i becomes 3), and finally i is 3, resulting in the output 3 2 3 3.