Switch case statement

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



  1. 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.
  2. 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

Popular posts from this blog

Function in C++ with example & declaration, initialization function in c++

Operators of c++

Storage class in c++