What will be the output of the following code? int main() {
What will be the output of the following code?
#include <stdio.h>
int main() {
int a = 2, b = 3;
switch (a) {
case 1:
printf("Case 1");
break;
case 2:
switch (b) {
case 3:
printf("Case 3");
break;
default:
printf("Inner Default");
}
default:
printf("Outer Default");
}
return 0;
}
Show answerHide answer
Correct answer: (D) Case 3Outer Default
Explanation
a = 2 selects case 2; the inner switch matches case 3, prints "Case 3", and its break exits only the inner switch. With no break after it, control falls into the outer default and prints "Outer Default".