In C++ switch statement, the expression of each case label must be an integer constant expression.
For example, the following program fails in compilation.
Putting const before i makes the above program work.
Note : The above fact is only for C++. In C, both programs produce error. In C, using a integer literal does not cause error.
Program to find the largest number between two numbers using switch case:
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Switch Statement in C/C++
- Interesting facts about switch statement in C
- Nested switch case
- Using range in switch case in C/C++
- Output of C programs | Set 30 (Switch Case)
- Local Labels in C
- What is the size_t data type in C?
- Is there any need of "long" data type in C and C++?
- What is data type of FILE in C ?
- Data type of character constants in C and C++
- Data Type Ranges and their macros in C++
- Conversion of Struct data type to Hex String and vice versa
- Break Statement in C/C++
- Continue Statement in C/C++
- goto statement in C/C++
Improved By : SantanuBasak