Switch Case Statement Example Program In C Programming Language


In C programming language, the switch statement is a type of selection mechanism used to allow block code among many alternatives.Simply, It changes the control flow of program execution via multiple blocks. 


Switch Statement Rules

  • A switch works with the char and int data types.
  • It also works with enum types
  • Switch expression/variable datatype and case datatype are should be matched.
  • A switch block has many numbers of case statements, Each case ends with a colon.
  • Each case ends with a break statement. Else all case blocks will execute until a break statement is reached.
  • The switch exists When a break statement is reached, 
  • A switch block has only one number of default case statements, It should end of the switch.
  • The default case block executed when none of the cases is true. 
  • No break is needed in the default case.

Switch Statement Usage

  • We can use switch statements alternative for an if..else ladder.
  • The switch statement is often faster than nested if...else Ladder.
  • Switch statement syntax is well structured and easy to understand.


switch ( <expression> or <variable> ) {
	case value1:
	 //Block 1 Code Here

	case value2:
	 //Block 1 Code Here

	 Code to execute for not match case

Example Program For Switch

/* Example Program For Switch Case In C Programming Language
  little drops @ thiyagaraaj.com
  Coded By:THIYAGARAAJ MP       */

// Header Files

//Main Function
int main()
  // Variable Declaration
  char ch;

  //Get Input Value
  printf("Enter the Vowel (In Capital Letter):");

  //Switch Case Check
  switch( ch )
    case 'A' : printf( "Your Character Is A\n" );

    case 'E' : printf( "Your Character Is E\n" );

    case 'I' : printf( "Your Character Is I\n" );

    case 'O' : printf( "Your Character Is O\n" );

    case 'U' : printf( "Your Character Is U\n" );

    default : printf( "Your Character is Not Vowel.Otherwise Not a Capital Letter\n" );
  // Wait For Output Screen

  //Main Function return Statement
  return 0;

Sample Output:

Enter the Vowel (In Capital Letter):A
Your Character Is A

Enter the Vowel (In Capital Letter):O
Your Character Is O

Enter the Vowel (In Capital Letter):h
Your Character is Not Vowel.Or Not a Capital Letter