C++ switch

C++ switch Statement :-

C++ switch statement tests the value of a variable against a no. of statements , when a match is found,  a block of statement associated with that case is executed.

Syntax:-

switch(expression){
case 1:
block;
break;

case 2:
block;
break;

default:
block;
break;
}

Example of C++ switch statement :-

#include<conio.h>
#include<iostream.h>
void main()
{
int a=12;
clrscr();
switch(a)
{
case 11:
cout<<"i am in case 11"<<endl;
break;
case 23:
cout<<"i am in case 23"<<endl;
break;
case 12:
cout<<"i am in case 12"<<endl;
break;
default :
cout<<"i am in default statement"<<endl;
}
getch();
}

 

Result of C++ switch :- 

C++ switch statement

  Examples Based on C++ switch statement.

 

 

 




Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top