Switch in c programming


Switch in C

switch is a selection control in programming language like c, c++, java etc..
It is used when user want to execute group of statement from available option it is used only with decimal integer constant or single character  constant.
Real(float,double) and string are not allowed in switch control.
It haves for keywords.( switch, case, break, default )
ANSI C permits the use of as many as 257 case labels.
ANSI C permits the use of nested switch statements. it is about  15 levels of nesting

Syntax

switch ( variable / constant / expression )
{
case value-1           :  block  1   ;   break ;
case value-2           :  block  2   ;   break ;
case value-N          :  block N   ;   break ;
default                    :  default block  ;
}
Next statement

 switch Examples program in Turbo C

 C Example program source code of integer constant passing in switch

Output of switch statement in C programming

Enter any Code for choose :
101 or 555 for Red color
202 or 18 or 456 for Yellow color
303 for Black color
*******************
18
It is Yellow

 


C Example program  of character constant passing in switch

Output of switch statement in C programming

Enter two values for (+, – ,*, /, % )
15
5
Enter your choice(+ – * / % )
*
Product = 75

(Visited 52 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *


CAPTCHA Image
Reload Image