C Language



Admission Enquiry Form

  

Switch Statement in C(With Integer)

What is Switch statement in C?

Switch statement is used to select one choice out of many in C.

Syntax of Switch statement...

switch(expression)
{
case 1:
//statements
break;
case 2:
//statements
break;
default:
//statements
}



Example of switch statement:


Output:

Following are the choices of Ice Cream...
Enter 1 for vanilla flavour
Enter 2 for butterscotch flavour
Enter 3 for chocolate flavour
3
You have got chocolate flavour

In the above example, if the user enters 1 case 1: will get executed till break. When break will be encountered the control will get out of the Switch block.The default will only be excecuted if user's choice does not match any of three cases.