In C, what kind of expression must control a switch statement?
Correct answer C. An expression of integer type, such as int, char or an enum
Explanation
The controlling expression of switch must have integer type, and each case label must be an integer constant expression. char and enum values qualify because they are integer types. A double is rejected, and strings cannot be switched on because comparing them needs strcmp rather than ==. For strings or ranges you write an if-else chain instead.
Answer checked How we write and check questions
Discussion