Question 11
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int x = 1, y = 2;
switch (x) {
case 1:
switch (y) {
case 2: printf("x1y2 "); break;
default: printf("x1 ");
}
printf("after-inner ");
break;
case 2:
printf("x2 ");
}
printf("\n");
return 0;
}
- A x1y2 after-inner Correct
- B x1y2
- C x1y2 x1 after-inner
- D x1y2 after-inner x2
Correct Answer: Option A
The inner break leaves only the inner switch, so "after-inner" still prints; the outer break then prevents falling into case 2.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!