What will be the output of the following C program segment?
char inchar = 'A';
switch (inchar)
{
case 'A' :
printf ("choice A \n") ;
case 'B' :
printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ;
}
Answer: C
Correct answer: Choice A Choice B No Choice
There is no break after the first printf, so execution falls through every following label. Matching case 'A' prints “choice A”, then “choice B”, then - passing through the empty labels C, D and E - the default prints “No Choice”. A case label marks an entry point, not a block.
Please log in or register to report this question.