Discussion
A typical “switch” body looks as follows:
switch (controlling_expression)
{
case label1:
/*label1 statements*/
break;
case label2:
/*label1 statements*/
break;
default:
/*Default statements*/
}
Which of the following statements about it is incorrect?
Answer: C
Correct answer: “switch” body may contain more than one “case” labels where the label value of these “case” is same and it would still compile. If “switch” controlling expression results in this “case” label value, the “case” which is placed first would be executed.
That statement is the incorrect one: duplicate case labels are a compile-time error. Each label must be a distinct constant, precisely so that the jump is unambiguous - there is no “first one wins” rule.
The other three are all true. A switch with no case at all compiles (and does nothing); default is optional, and control simply skips the switch if nothing matches; and omitting break is legal, producing fall-through.
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