Multiple choice

int a=10,b; b=a++ + ++a; printf(%d,%d,%d,%d,b,a++,a,++a); What will be the output when following code is executed?

  1. 12,10,11,13

  2. 22,10,11,13

  3. 22,11,11,11

  4. 12,11,11,11

  5. 22,13,13,13

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

Starting with a=10: b = a++ + ++a = 10 + 12 = 22. After this, a=13 (a++ made it 11, ++a made it 12, then sequence completes at 13). In printf: b=22 (no change), a++ prints 13 then makes a=14, a prints 14, ++a makes a=15 then prints 15. Output: 22,13,13,13. This demonstrates undefined behavior in C - the order of evaluation of printf arguments is not specified.