Switch case outside statement
In this tutorial we will be learning how switch case outside statement is written in switch case.
C Switch case outside statement
Consider the below program, if you observe program carefully then you would understand that first printf statement is switch case outside statement
int main() { int choice = 1 ; switch(choice) { printf("\nFirst Statement"); case 1 : printf("\nInside Switch case 1"); break; case 2 : printf("\nInside Switch case 2"); break; case 3 : printf("\nInside Switch case 3"); break; } return(0); }
Output :
Inside Switch case 1
Explanation
Before reading the solution keep important switch case rule in mind that - Every Statement in switch must be wrapped within any of the case.
Recommended Article : Rules of writing switch case statement
In the above example,
printf("\nFirst Statement");
is nothing but switch case outside statement, so it is not considered as a part of any of the switch case so it is neglected by compiler
Above picture explains everything, You would be able to identify the blocks which are not the part of any case blocks