C

Chandani • 9.81K Points
Tutor III

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");
    }
}
  • (A) Well done
  • (B) You passed
  • (C) Better try again
  • (D) All of these

Explanation by: Chandani
There is no break statement in case B, Case C, case D. the code will fall through executing all the print statements.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.


Question analytics