What will be the output of the program?
#include <stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf("Hello\n");
case 1:
printf("Hi\n");
break;
case 2:
printf("\nBye\n");
break;
}
return 0;
}
Answer: C
Correct answer: Hi
A switch jumps directly to a matching label, so the printf("Hello") written before any case is unreachable. i is 1, so control lands on case 1, prints Hi, and the break ends the switch.
Please log in or register to report this question.