Difficulty: Easy
Correct Answer: Error: LValue required in strcpy
Explanation:
Introduction / Context:Declaring an object as const in C makes the entire object read-only. For aggregates such as structs and unions, each member becomes non-modifiable through that object. Attempting to write into a member via functions like strcpy therefore violates const-correctness and must be diagnosed by the compiler. This question highlights how const applies transitively to members of a union and how that affects typical string-copy operations.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Check object qualification: e1 is const → all members non-modifiable.strcpy destination requires writable memory → e1.name is not writable.Compilation fails with an error indicating invalid attempt to write to a const object.Verification / Alternative check:
If e1 were non-const, strcpy would compile; or, if you used a separate writable buffer, no error would occur.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
Error: LValue required in strcpy
Discussion & Comments