The switch statement is very useful while writing menu driven programs. Sometimes there is need in program to make choice among number of alternatives. For this purpose we use switch statement.

switch( expression )
{
    case constant1: statement;
                              ...............
                              ...............
    case constant2: statement;
                              ...............
                              ...............
    .
    .
    .
     case constantN: statement;
                              ...............
                              ...............
    default : default statement;
}

Here switch, case and default are keywords. The expression following switch keyword is any C expression that yields an integer value. The keyword case is followed by an integer or character constant. Each constant must be different from other.
Let us see how the switch statement works. First, the expression following the the keyword switch is evaluated. The value of this expression is then compared one by one with constant values that follow the case keyword. When a match is found, then all statements under that particular case are executed, and all subsequent case and default statement as well. If no match is found, then only statements following the keyword default are executed.

int main()
{
int i=3;
switch(i)
  {
    case 1: printf("One \n");
    case 2: printf("Two \n");
    case 3: printf("Three \n");
    case 4: printf("Four \n");
    default: printf("Wrong Choice \n");
  }
return 0;
}

The output of above program:
Three
Four
Wrong Choice

But here we want only case 3.  For this we have to use break statement. So  the above program is written as :

int main()
{
int i=3;
switch(i)
  {
    case 1: printf("One \n");
                 break;
    case 2: printf("Two \n");
                 break;
    case 3: printf("Three \n");
                 break;
    case 4: printf("Four \n");
                 break;
    default: printf("Wrong Choice \n");
  }
return 0;
}

The output of this program would be:
Three

There is no need for a break statement after default. Here multiple statements are executed in each case, but there is no need to enclose them within pair of braces.

Find output of following program ...