Difficulty: Easy
Correct Answer: 1
Explanation:
Introduction / Context:
In C, every struct definition must end with a semicolon after the closing brace. This question tests attention to syntax details and the difference between a definition and a variable declaration that may follow it.
Given Data / Assumptions:
Concept / Approach:
The grammar requires a semicolon after a struct or enum declaration list. Omitting it causes a compilation error. Only snippet (1) shows the required semicolon; snippets (2) and (3) omit it.
Step-by-Step Solution:
Inspect (1): has closing brace followed by semicolon → valid.Inspect (2) and (3): missing the terminating semicolon → invalid.Therefore, only option (1) is correct.
Verification / Alternative check:
Compiling (2) or (3) results in a diagnostic such as “expected ‘;’ after struct declaration.” Adding the semicolon fixes the error.
Why Other Options Are Wrong:
2, 3, and “All of the above” include definitions without the required semicolon.1 and 2: includes an invalid definition.
Common Pitfalls:
Forgetting the semicolon; confusing a struct definition with a variable declaration that might follow on the same line (e.g., struct T { ... } x;).
Final Answer:
1
Discussion & Comments