Switch statement in ANSI C and flow chart to explain switch

In C, the control statement that allows you to make a decision from the number of choices is called a switch, or a switch case- default, since these three keywords go together to make up the control statement. Syntax of switch:

switch ( integer expression )
{
case constant 1 :
do this ;
case constant 2 :
do this ;
case constant 3 :
do this ;
default :
do this ;
}

The integer expression following the keyword switch is any C expression that will yield an integer value. It could be an integer constant like 1, 2 or 3, or an expression that evaluates to an integer. The keyword case is followed by an integer or a character constant. Each constant in each case must be different from all the others. The “do this” lines in the above form of switch represent any valid C statement.

Click here, for flow chart of switch statement.

Speak Your Mind

*


− five = 2