πŸ“Š C Programming
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
πŸ’¬ Discuss
βœ… 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.

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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
239
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Chandani
Publisher
πŸ“ˆ
95%
Success Rate