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 an error. In C, using an integer literal does not cause an 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)
- Is there any need of "long" data type in C and C++?
- What is data type of FILE in C ?
- What is the size_t data type 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
- Local Labels in C
- Print individual digits as words without using if or switch
- Break Statement in C/C++
- goto statement in C/C++