Difficulty: Easy
Correct Answer: Duplicate case case 5:
Explanation:
Introduction / Context:This question focuses on constant expressions in case labels and the prohibition of duplicate case values. It also checks the misconception that every case must end with a break to compile.
Given Data / Assumptions:
3 + 2.5.break.Concept / Approach:Case labels must be integer constant expressions, and duplicates are illegal. The expression 3 + 2 is a constant expression that evaluates to 5 at compile time, colliding with the later case 5:. Missing break may cause fall-through, but that is a runtime behavior choice, not a compile error.
Step-by-Step Solution:Evaluate 3 + 2 → 5.Detect duplicate labels: case 3 + 2 and case 5 both equal 5.Compiler emits duplicate case label error.
Verification / Alternative check:Replace one of the labels with a distinct constant (e.g., 6) and compilation succeeds, regardless of missing break statements.
Why Other Options Are Wrong:Expression not allowed — constant expressions are allowed. No break in each case — not a compile error. No error — incorrect due to duplication.
Common Pitfalls:Forgetting that constant expressions are folded at compile time; believing break is mandatory.
Final Answer:Duplicate case case 5:
Discussion & Comments