The switch statement in C can judge expressions of integer, character and enumeration types. The working principle is to transfer the control flow to the matching branch according to the expression value. If not matched, the default branch will be executed. The syntax is: switch (switch expression) { case constant 1: code; break; case constant 2: code; break; ... default: code; break; }
The type of switch statement judgment in C
The switch statement in C is a control structure that allows different executions based on the value of an expression (called a switch expression) code block. The switch statement can determine the following types of expressions:
Working principle
The switch statement is based on the value of the switch expression , transfer the control flow to the case branch matching this value. If no matching branch is found, the default branch is executed (if there is one).
Syntax
<code class="cpp">switch (开关表达式) { case 常量1: // 当开关表达式等于常量1 时执行的代码 break; case 常量2: // 当开关表达式等于常量2 时执行的代码 break; // ... default: // 当开关表达式不等于任何常量时执行的代码 break; }</code>
Notes
The above is the detailed content of What type can switch in c++ determine?. For more information, please follow other related articles on the PHP Chinese website!