COMPUTER SOFTWARE
PROGRAMMING LANGUAGES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
floating point
|
|
integer
|
|
long integer
|
|
all above
|
Detailed explanation-1: -Ans: No, floating-point numbers cannot be used in a switch statement in C. Only integers or character types are allowed.
Detailed explanation-2: -Switch case allows only integer and character constants in case expression. We can’t use float values. It executes case only if input value matches otherwise default case executes. Break keyword can be used to break the control and take out control from the switch.
Detailed explanation-3: -The value of the expressions in a switch-case statement must be an ordinal type i.e. integer, char, short, long, etc. Float and double are not allowed.
Detailed explanation-4: -A case or default label can only appear inside a switch statement. The constant-expression in each case label is converted to a constant value that’s the same type as condition . Then, it’s compared with condition for equality.
Detailed explanation-5: -Float cannot be checked in a switch-case statement.