Multiple choice

What will be the output of the given program? #include<stdio.h> #include<conio.h> int main() { char x='G'; switch(x) { if(x=='B') { case 'd': printf(%c,'o'); case 'B': printf(%s,Bad); } else { case 'G': printf(%s,Good); default: printf(%s,Boy); } } getch(); }

  1. GoodBoy

  2. Good

  3. Boy

  4. None of these

  5. Error in the program

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The program will switch the statements with the value x=’G’. If (x==’B’), then if part will be executed. But x is equal to ‘G’. So, else part will be executed. Now the question arises that why default is executed. As we can see that else part contains the default part. Therefore, default is also executed with case ‘G’. So, the result is GoodBoy.