C Programming
Switch StatementIn switch statement we test the single constant variable or value with different case value and if matched value found then body of case is executed and terminated by break statement. As soon as break statement is executed the control return back from switch. And If no matched value found then default statement is executed and switch terminated.
Syntax
switch(expression) { case constant-expression : statement(s); break; case constant-expression : statement(s); break; default : statement(s); }
Example
int main () { char vowel = 'b'; switch(vowel) { case 'a' : printf("Vowel\n" ); break; case 'e' :
printf("Vowel\n" );
break;
case 'i' :
printf("Vowel\n" );
break;
case 'o' : printf("Vowel\n" ); break; case 'u' : printf("Vowel\n" ); break; default : printf("Consonant\n" ); } }
Output: Consonant
C Programming