Syntax And Define Switch Statement In C Programming Language
Define switch statement in C language? What is the syntax for the switch statement? What are the rules for using a switch statement?
Define switch statement in C language? What is the syntax for the switch statement? What are the rules for using a switch statement?
The switch statement is a control statement that allows us to choose one option from many options. The expression is evaluated to return an integral value, which is compared to the different values present in each case. If there is no match, then the default block is executed. The syntax is
Switch(expression)
{
Case value- 1:
Block1;
Break;
Case value-2:
Block2;
Break;
.
.
.
Case value- n:
Block n;
Break;
Default:
Default-block;
Break;
}
Rules for using a switch statement:
1. The expression must yield an integer value or a variable; it must not be a null value.
2. The Value must be unique.
3. Case name should not end with a colon.