Switch/case

Text
Last edited on
According to the C++ Standard "2 The condition shall be of integral type, enumeration type, or of a class type for which a single non-explicit
conversion function to integral or enumeration type exists"

Of course the switch can be substituted for if-else. However using switch sometimes makes your code more clear and readable.
Ok
Last edited on
char is an integral type so you can use it in a switch.
Character arrays are not integral types. So you may not use them. You can not compare arrays as a1 == a2 or a1 == "a". because there is no such operator for arrays.
Last edited on
closed account (zb0S216C)
Because strings are pointers and pointers are not convertible to integral values. Character constants are convertible to integral values, however. The compiler requires switch labels to be constant integral expressions.

Wazzak
Last edited on
Ok, thanks for the answers.
Last edited on
Topic archived. No new replies allowed.