C Programming Reference >> C Basic Tutorials >> C Keywords Home >> switchui 30/12/06 - Views - Ratings : Its a multiple selection statement. Several cases are coded. When value is passed to switch, the execution of code start where case is match and dont stop until it comes across a break statement. If no case match default case is executed if available. Only int and char constants can be used as case paramenters. Swithc is most commonly used to generate menus. Code - void function (void)
{
char ch;
printf ("\nEnter Character A,B or C: ");
ch = getchar ();
switch (ch)
{
case 'A' : printf ("You Entered A");
break;
case 'B' : printf ("You Entered B");
break;
case 'C' : printf ("You Entered C");
break;
default : printf ("You Didnot Entered A, B or C");
}
}
|