Thursday, July 30, 2009

In turbo_c programming.What is afunction of a switch command?

I'm searching the functions of switch command,to know what is its functios and to know how to use this command.

In turbo_c programming.What is afunction of a switch command?
it's used in place of multiple if-else blocks.


switch is mainly used to execute different blocks of code, depending upon a value of a variable.





for eg.


int choice;


//input choice





switch(choice)


{


case 1: printf("u input 1");


break;


case 2: printf("u input 2");


break;


default : printf("some thing else");


}





Remember to give a break statement after each case, otherwise after one case, the other case will also be executed.
Reply:switch is not a command, it's key word.





See the previous answer for details on how to use it.
Reply:In nearly all the programming languages,'switch is used for multi-conditional operator.The statement analyses many statements to give one proper result.It is used for event oriented programming


No comments:

Post a Comment