Multiple choice

What will be the output for the following? int i=2; if(i) cout<<i++; else cout<< --i;

  1. 2

  2. 1

  3. 3

  4. 0

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

The integer i=2 is non-zero, which evaluates to true in the if condition. The if branch executes, printing i++ using post-increment. Post-increment returns the current value (2) then increments, so 2 is printed. The else branch is never reached.