Consider the following C program:
#include <stdio.h> void main()
{ int a = 2;
switch (a)
{
case 4: printf ( "A" );
break ;
case 3: printf ( "B" );
default : printf ( "C" );
case 1 : printf ( "D" );
break ;
case 5 : printf ( "E" );
}
} |
(A) Printed: A
(B) Printed: E
(C) Printed: CD
(D) None
Answer: (C)
Explanation: In switch statement default should be at mentioned after all the switch cases. In this case, it gets executed in between and all cases after default are executed before a break statement.
#include <stdio.h> void main()
{ int a = 2;
switch (a)
{
case 4: printf ( "A" );
break ;
case 3: printf ( "B" );
default : printf ( "C" );
case 1 : printf ( "D" );
break ;
case 5 : printf ( "E" );
}
} |
Option (C) is correct.
Quiz of this Question
Article Tags :
Recommended Articles