When 2 is entered, The output of the code below is?
#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 1 to 2:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("1\n");
break;
printf("Hi");
default:
printf("2\n");
}
}
Answer: D
Correct answer: 2
ch is 2, which matches no case, so control goes straight to default and prints 2. The printf("Hi") is unreachable in any event: it sits immediately after a break and before the next label, so no path can reach it.
Please log in or register to report this question.