Question: Task 2: switch-case Statement: switch-case statement is similar to if statement in giving you multiple options and do actions accordingly! Syntax: } switch-case statement tests

 Task 2: switch-case Statement: switch-case statement is similar to if statement
in giving you multiple options and do actions accordingly! Syntax: \} switch-case
statement tests whether an expression matches one of a number of constant

Task 2: switch-case Statement: switch-case statement is similar to if statement in giving you multiple options and do actions accordingly! Syntax: \} switch-case statement tests whether an expression matches one of a number of constant values labeled as cases. If one matches the expression, execution starts at that case. If none of the cases matches, the statements under default clause will be executed. default clause is optional. If it is not there and none of the cases matches, no action is taken. default is similar to else in if-else-if. break keyword is used to exit switch-case statement, if a case matches the expression and no break key word is used, the execution will continue through the statements until a break statement is found or the end of the switch statement is reached. switch-case statement checks only equality of the same variable (expression) with specific values following the case words. Comparison operators cannot be used. In the next page is the same program shown in Task 1 using swi tch-case statement. Three main remarks regarding switch: 1. Data type of the expression and labels must be integer. 2. Break statement 3. Default is not compulsory Save the source file as Lab 4 /program3.c 2. 3. nn 4. Remove break statement from the above program. Save the modified program as Lab4 / program4 . c. Compile and debug the program. Observe the execution flow of the program! (See Slide \#48 os Lecture \#3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!