Multiple choice technology programming languages

What is the output?int i = 3;if (!i) i++; i++;if (i==3) i+=2; i+=2;printf("%d\n", i);

  1. 3

  2. 5

  3. 7

  4. 6

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

The key is understanding if-statement scope: only the immediately following statement is controlled by the if. int i = 3; if (!i) i++; - !3 is 0 (false), so i++ doesn't execute. i++; now executes (unconditional), i becomes 4. if (i==3) i+=2; - 4 != 3 (false), so i+=2 doesn't execute. i+=2; now executes (unconditional), i becomes 6. printf prints 6. Option D is correct.