Multiple choice

What would be the output of the following?

main() { int i=4; switch(i) { default: printf(“A”); case 1: printf(“B”); break; case 2: printf(“C”); break; case 3: printf(“D”); break; } }

  1. A

  2. B

  3. All the above

  4. None of the above

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

The switch statement has choice=4. There is no case 4, so execution goes to default. The default prints "A" but has NO break statement. Without break, execution falls through to case 1, which prints "B". The output is "AB". Looking at the options, none of A, B, C ("All the above") match "AB". Therefore D (None of the above) is correct.