GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 27

Consider the following C program:

filter_none

edit
close

play_arrow

link
brightness_4
code

#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"); 
    
}

chevron_right


(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.

filter_none

edit
close

play_arrow

link
brightness_4
code

#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"); 
    
}

chevron_right


Option (C) is correct.

Quiz of this Question



My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.