C Programming - Control Instructions - Discussion


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?

[A]. Yes
[B]. No

Answer: Option A


We can do this in following switch statement

    case 2:
    case 3:
    case 4:
       /* some statements */
    case 5:
    case 6:
    case 7:
       /* some statements */

Kamal said: (Mar 18, 2011)  
It is only true when we are concerned with integer values.

Leszek said: (Jun 10, 2012)  
THis question is wrong. Correct answer is "Maybe we can, maybe we can't. Depends on the value we want to test".

Abhinav said: (Jul 24, 2014)  
This should not be the right answer, won't hold if we are considering non integer values.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.