Discussion
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.
Answer: B
Correct answer: 1,3,4
1 is true - a switch compares the controlling expression against a set of discrete constants. 3 is true: where the labels are dense the compiler typically builds a jump table, which is why a switch can beat a chain of ifs. 4 is true: omitting break is legal and produces deliberate fall-through.
2 is false. A switch cannot test a range - each value in the range needs its own label - which is what if-else if is for.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development