C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 9)
9.
Which of the following sentences are correct about a switch loop in a C program?
1: switch is useful when we wish to check the value of variable against a particular set of values.
2: switch is useful when we wish to check whether a value falls in different ranges.
3: Compiler implements a jump table for cases used in switch.
4: It is not necessary to use a break in every switch statement.
1,2
1,3,4
2,4
2
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
17 comments Page 2 of 2.

Mrunali said:   1 decade ago
We can use it but it is not efficient and hence not preferred. Instead we can use an if statement to check for a range of values.

Eg. to check whether value of variable x lies between 0 and 100.

1.switch-case

switch(x)
{
case 0:
case 1:
case 2:
.
.
.
.
case 99:
case 100:printf("True");break;
default: printf("False");break;
}

//This is very long and tedious and hence not useful. Instead we can Accomplish this in a few lines only using if statement.

2.if-else

if(x>=0 && x<=100)
printf("True");
else printf("False");

Ramyaa said:   1 decade ago
Each and every case should have break condition. Whether it is mandatory?

Ravi said:   1 decade ago
It is not necessary to use a break in every switch statement.

We use break in case statement not in switch.

Mounika said:   9 years ago
We can't check the ranges of non-integer values through switch statement, and so switch is not useful in checking the ranges of a number.

Mounika said:   9 years ago
We can't check the ranges of non-integer values through switch statement, and so switch is not useful in checking the ranges of a number.

Venkata said:   9 years ago
Can we wrote switch statement without cases? Please anyone tell me.

Kartik Agarwal said:   8 years ago
Why statement 2 is wrong?

We can check for ranges.

/*example*/
switch(a)
{
case 2:
case 3:
case 4:
/* some statements */
break;
case 5:
case 6:
case 7:
/* some statements */
break;
}
(1)


Post your comments here:

Your comments will be displayed after verification.