Switch Case Statement

The switch statement is a multway statement. If there is a possibility to make a choice from given options, this structured selection is useful. The switch statement only requires one argument of any data type to be checked with the given number of case options.

Here switch, case and default are reserved keywords and every case statement terminates with colon(:)
It is mainly used for menu driven programs.

Syntax and working of switch statement:

switch ( variable or expression )
{
  case constant A:
    statement;
    break;

  case constant B
    statement;
    break;
    .
    .
    .
case constant n
    statement;
    break;

default:
    statement;
}

Flow chart of switch statement:

Flow chart of Switch Case Statement

Example of switch case statement: