C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Yes / No Questions (Q.No. 3)
3.
We want to test whether a value lies in the range 2 to 4 or 5 to 7. Can we do this using a switch?
Yes
No
Answer: Option
Explanation:
We can do this in following switch statement

switch(a)
{
    case 2:
    case 3:
    case 4:
       /* some statements */
       break;
    case 5:
    case 6:
    case 7:
       /* some statements */
       break;
}
Discussion:
3 comments Page 1 of 1.

Abhinav said:   10 years ago
This should not be the right answer, won't hold if we are considering non integer values.

Leszek said:   1 decade ago
THis question is wrong. Correct answer is "Maybe we can, maybe we can't. Depends on the value we want to test".

Kamal said:   1 decade ago
It is only true when we are concerned with integer values.

Post your comments here:

Your comments will be displayed after verification.