Can anyone tell what is specialty of Switch case statement in c language ?
I can replace switch case a statement with multiple if statement as shown in second program. I do not think that switch case statement should be needed because I can make it with multiple if statement. But this is not a true, it is used at many places. What I am missing about Switch case statement ?
This is example of switch case statement
This example show the behavior of switch case
I can replace switch case a statement with multiple if statement as shown in second program. I do not think that switch case statement should be needed because I can make it with multiple if statement. But this is not a true, it is used at many places. What I am missing about Switch case statement ?
This is example of switch case statement
C:
#include<stdio.h>
int main ()
{
int N;
printf("input : ");
scanf("%d", &N);
switch (N)
{
case 1:
printf("First \n");
break;
case 2:
printf("Second \n");
break;
case 3:
printf("Third \n");
break;
default:
printf("None \n");
break;
}
return 0;
}
C:
#include<stdio.h>
int main ()
{
int N;
printf("input : ");
scanf("%d", &N);
if(N==1)
printf("First \n");
if(N==2)
printf("Second \n");
if(N==3)
printf("Third \n");
else
printf("None \n");
return 0;
}