C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - General Questions (Q.No. 5)
5.
Which of the following cannot be checked in a switch-case statement?
Character
Integer
Float
enum
Answer: Option
Explanation:

The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.


switch( expression )
{
    case constant-expression1:    statements 1;
    case constant-expression2:    statements 2;    
    case constant-expression3:    statements3 ;
    ...
    ...
    default : statements 4;
}

The value of the 'expression' in a switch-case statement must be an integer, char, short, long. Float and double are not allowed.

Discussion:
18 comments Page 2 of 2.

Manojit said:   1 decade ago
The switch/case statement convert the float into an int and use it, so long as the resulting values and functionality meet your functional requirements.

Vinita said:   1 decade ago
Thanks Pruthvi.

Pruthvi said:   1 decade ago
Yes. Enum can be checked. As an integer value is used in enum.

Diya said:   1 decade ago
Can enum be checked in a switch-case statement?

Praveen said:   1 decade ago
Why enum cannot be the answer? Any reason......

Tarun Singh KiiT said:   1 decade ago
Switch case does not accept the float value.

Hemanth said:   1 decade ago
Why enum cannot be the answer? Any reason plzzzzz.

K.suriya said:   1 decade ago
Case value must be an int, char, enum but not double and float float is the answer for this question.


Post your comments here:

Your comments will be displayed after verification.