GATE 2012 CS (CS1) – Question 13
Find the output of the printed C fragment. Several case labels below retain the source’s semicolons.
char inChar='A';
switch (inChar) {
case 'A': printf("Choice A\ n");
case 'B';
case 'C': printf("Choice B");
case 'D';
case 'E';
default: printf(" No Choice");
}Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: MTA
Explanation
The final key gives marks to all. Literally, the printed semicolons after case B,D,E are invalid case-label syntax. If repaired to colons, lack of break causes fall-through from A through the later print statements, producing Choice A followed by Choice B and No Choice. Preserve universal credit and disclose the source defect.