C Language: Chapter 4 The case control structure.
Switch is the case control statement that allows us to make a decision from the number of choices.
It is also called switch case default. These three keywords go together to make up the control statement.
Syntax of switch case default
- The integer expression following the switch keyword is any c expression that yields the integer value. [Characters also since they do have ASCII value interpretations]
- It could be an integer constant like 1, 2 or 3 or any expression that evaluates to an integer.
- The keyword case followed by an integer constant or character constant.
- Each constant in each case must be different from all other cases.
The integer expression following the keyword switch is evaluated and yields an integer value.
The integer value must be matched across the cases.
When a match is found-The program executes following
1. The statement following that case.
2. All subsequent cases.
3. Default case as well.
Keyword break stops executing the subsequent cases and default cases.
It is not necessary to use default case in switch structure.




Comments
Post a Comment