C Switch Statement
The statement that enables us to choose the number of alternatives is referred to as a switch.
The switch case-default statement syntax:
switch
(integer expression)
{
case 1:
do this;
case 2:
do this;
case 3:
do this;
default:
do this;
}
Example
#include
<stdio.h>
int main()
{
int i
= 3;
switch
(i)
{
case 1:
printf("I am Statement 1");
break;
case 2:
printf("I am Statement 2");
break;
case 3:
printf("I am Statement 3");
break;
default:
printf("I am default");
break;
}
return
0;
}
Output:
I am Statement 3