Switch case
Switch case statement allow us to execute one statement from many statement are that statement is called case. Actually in which statement, inside the body of switch a number of case are used and a perameter are passed and from which case this parameter is matched, execute.
Syntax
- In the statement a value/number is passed in the place of parameter and that case will execute which is equal to that value/ number.
- If no case matched with parameter then default case will execute.
Example
#include<stdio.h>
int main()
{
//Assigning parameter's value
int p=2;
switch(p)
{
case 1:
cout<<"it is case 1";
break;
case 2:
cout<<"it is case 2";
break;
case 3:
cout<<"it is case 3";
break;
default:
cout<<"no case matched";
}
return 0;
}
### output ###
it is case 2
//because p=2 so case 2 will execute
Comments
Post a Comment
If you have any doubt. Please comment me know.