Point out the error, if any in the program.
#include <stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf("This is c program.");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
Answer: C
Correct answer: No Error and prints "Case1"
The printf before the first case is legal but unreachable: a switch transfers control straight to a matching label, so nothing before the first label ever runs. i is 1, so case 1 executes and the break ends the switch.
Please log in or register to report this question.