C Programming - Control Instructions - Discussion
Read more: "Everything should be made as simple as possible, but not simpler."
- Albert Einstein
5.
Which of the following cannot be checked in a switch-case statement?
[A].
Character [B].
Integer [C].
Float [D].
enum
Answer: Option E
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.
K.Suriya said:
(Sat, May 14, 2011 12:59:56 PM)
Case value must be an int, char, enum but not double and float float is the answer for this question.
Hemanth said:
(Sat, Jul 23, 2011 05:38:44 PM)
Why enum cannot be the answer? Any reason plzzzzz.
Tarun Singh Kiit said:
(Sat, Jul 30, 2011 03:32:59 PM)
Switch case does not accept the float value.
Praveen said:
(Tue, Aug 2, 2011 08:56:12 PM)
Why enum cannot be the answer? Any reason......
Diya said:
(Tue, Aug 2, 2011 09:55:42 PM)
Can enum be checked in a switch-case statement?
Pruthvi said:
(Sun, Sep 4, 2011 02:27:27 AM)
Yes. Enum can be checked. As an integer value is used in enum.
Vinita said:
(Wed, Oct 12, 2011 09:42:29 PM)
Thanks Pruthvi.
Manojit said:
(Sat, Feb 11, 2012 07:41:08 PM)
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.
Rangasamy said:
(Sun, Jul 1, 2012 11:43:27 PM)
Can you explain the use of enum in switch statement with a program ?