Output of C programs | Set 30 (Switch Case) Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 48 Likes Like Report Prerequisite - Switch Case in C/C++ Interesting Problems of Switch statement in C/C++ Program 1 C #include <stdio.h> int main() { int num = 2; switch (num + 2) { case 1: printf("Case 1: "); case 2: printf("Case 2: "); case 3: printf("Case 3: "); default: printf("Default: "); } return 0; } Output: Default: Explanation: In switch, an expression "num+2" where num value is 2 and after addition the expression result is 4. Since there is no case defined with value 4 the default case got executed. Program 2 C #include<stdio.h> void main() { int movie = 1; switch (movie << (2 + movie)) { default: printf(" Traffic"); case 4: printf(" Sultan"); case 5: printf(" Dangal"); case 8: printf(" Bahubali"); } } Output: Bahubali Explanation: We can write case statement in any order including the default case. That default case may be first case, last case or in between the any case in the switch case statement. The value of expression "movie << (2 + movie)" is 8. Program 3 C #include<stdio.h> #define L 10 void main() { auto a = 10; switch (a, a*2) { case L: printf("ABC"); break; case L*2: printf("XYZ"); break; case L*3: printf("PQR"); break; default: printf("MNO"); case L*4: printf("www"); break; } } Output: XYZ Explanation: In C, comma is also operator with least precedence. So if x = (a, b); Then x = b Note: Case expression can be macro constant. Program 4 C #include<stdio.h> void main() { switch(2) { case 1L: printf("No"); case 2L: printf("%s","GEEKS"); goto Love; case 3L: printf("Please"); case 4L:Love: printf("FOR"); } } Output: GEEKSFOR Explanation: It is possible to write label of goto statement in the case of switch case statement. This article is contributed by Mr. Somesh Awasthi. Comment K kartik 48 Improve K kartik 48 Improve Article Tags : C Language C-Output Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C6 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like