How to use the switch case? explain and give me an example.
`switch` statement in the C language:
`switch` is a control statement used to perform different actions based on different conditions.
It evaluates an expression and compares it with constant integral values (integers or characters) in `case` labels.
Syntax:
```c
switch (expression) {
case constant1:
// Code to be executed if expression matches constant1
break;
case constant2:
// Code to be executed if expression matches constant2
break;
// ... more cases
default:
// Code to be executed if expression doesn't match any case
}
```
The `break` statement is used to exit the `switch` block after a case is executed to prevent fall-through to the next case.
`default` is optional and executed if none of the cases match the expression.
If no `break` is used, execution falls through to the next case, and all subsequent cases are executed until a `break` or the end of the `switch` block is reached.
#CLanguage
#ProgrammingInC
#CProgramming
#CodeInC
#LearnC
#CodersInC
#ProgrammingLanguage
#ComputerProgramming
#CodersCommunity