![]() In this program, since the value stored in variable num is eight, a switch will execute the case whose case-label is 8.A switch construct is used to compare the value stored in variable num and execute the block of statements associated with the matched case.In the given program we have explain initialized a variable num with value 8.Once the switch is executed the control will go to the statement-x, and the execution of a program will continue.įollowing diagram illustrates how a case is selected in switch case: How Switch Worksįollowing program illustrates the use of switch: #include.Otherwise, it is not necessary to write default in the switch. Whenever the value of test-expression is not matched with any of the cases inside the switch, then the default will be executed. ![]() Break will terminate the case once it is executed and the control will fall out of the switch. This should not happen hence we always have to put break keyword in each case. If we do not put the break in each case then even though the specific case is executed, the switch in C will continue to execute all the cases until the end is reached.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |