Question discussion

What will be the output of the following code?

358825Medium DSSSB TGT Computer Science 0 replies 0 views
0
What will be the output of the following code?
#include <stdio.h>
int main() {
    int x = 5;
    switch(x) {
        case 5:
            printf("Five");
        default:
            printf("Default");
    }
    return 0;
}
  • ADefault
  • BCompilation error
  • CFive
  • DFiveDefault
Correct answer: D

Explanation

x = 5 matches case 5 and prints "Five". There is no break, so execution falls through to default and prints "Default". The output is FiveDefault.

Discussion 0

Nobody has replied yet. Start the discussion!