Practice mode C Language

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.