Skip to content
Related Articles

Related Articles

Improve Article

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

  • Last Updated : 06 Nov, 2020

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

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.




My Personal Notes arrow_drop_up
Recommended Articles
Page :