Q. What will be the output of the following C code?
Code:
#include <stdio.h>
int main(){
char grade = 'B';
switch (grade) {
case 'A':
printf("Excellent!\n");
case 'B':
case 'C':
printf("Well done\n");
case 'D':
printf("You passed\n");
case 'F':
printf("Better try again\n");
break;
default:
printf("Invalid grade\n");
}
}
β
Correct Answer: (D)
All of these
Explanation: There is no break statement in case B, Case C, case D. the code will fall through executing all the print statements.