Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of the following statement is correct for switch controlling expression?

  • A.Only int can be used in “switch” control expression
  • B.Both int and char can be used in “switch” control expression.
  • C.All types i.e. int, char and float can be used in “switch” control expression
  • D.“switch” control expression can be empty as well

Answer: B

Correct answer: Both int and char can be used in “switch” control expression.

The controlling expression must have an integer type. char qualifies - it is a small integer type and is promoted to int - as do short, long and enumerations. float and double do not, because equality against a case label would be unreliable for values that cannot be represented exactly. The expression also cannot be omitted.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.