What will be the output of the program?
#include <stdio.h>
int main()
{
int i=4;
switch(i)
{
default:
printf("This is default\n");
case 1:
printf("This is case 1\n");
break;
case 2:
printf("This is case 2\n");
break;
case 3:
printf("This is case 3\n");
}
return 0;
}
Answer: A
Correct answer: This is default This is case 1
i is 4, which matches no case, so control jumps to default - and default need not be last. Having no break, execution then falls through into case 1, whose break finally ends the switch. So two lines are printed.
Please log in or register to report this question.