GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 27
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
Last Updated :
06 Nov, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...