Switch Statement
The switch statement cause a particular group of statements to be chosen from several available groups. The selection is based upon the current value of an expression that is include within the switch statement.
The form of switch statement is
switch (integer expression)
{
case constant 1:
do this;
case constant 2 :
do this;
case constant 3 :
do this;
default:
do this;
}
Example:-
int main ( )
{
int num = 2;
switch (num +2)
{
case 1:
printf("case 1 : Value is : %d", num);
case 2:
printf("Case 1: Value is : %d", num);
case 3 :
printf("Default : Value is : %d", num);
default :
printf("Default : Value is : %d", num);
}
return 0;
}
The switch statement cause a particular group of statements to be chosen from several available groups. The selection is based upon the current value of an expression that is include within the switch statement.
The form of switch statement is
switch (integer expression)
{
case constant 1:
do this;
case constant 2 :
do this;
case constant 3 :
do this;
default:
do this;
}
Example:-
int main ( )
{
int num = 2;
switch (num +2)
{
case 1:
printf("case 1 : Value is : %d", num);
case 2:
printf("Case 1: Value is : %d", num);
case 3 :
printf("Default : Value is : %d", num);
default :
printf("Default : Value is : %d", num);
}
return 0;
}
0 Comments:
Post a Comment