Difficulty: Easy
Correct Answer: Correct
Explanation:
Introduction / Context:This conceptual question asks whether a union may contain another union (directly or via a member that is itself a union) in standard C. Understanding type composition rules helps in designing compact variant data structures.
Given Data / Assumptions:
Concept / Approach:Standard C permits composing structs and unions from other structs and unions. A union member can be another union or a struct, and vice versa. Restrictions apply only to incomplete types and to members that would create infinite recursion by value (but pointers to the same type are fine).
Step-by-Step Solution:
1) Recall that structs and unions are aggregate types and may contain other aggregate types as members.2) A union U can have a member union V; the layout reserves enough space for the largest member.3) Self-embedding by value would be invalid due to infinite size, but nesting distinct unions is valid.Verification / Alternative check:Example compiles: union V { int x; float y; }; union U { union V v; int k; } u; This is valid in standard C.
Why Other Options Are Wrong:
Common Pitfalls:Confusing “nested by value” with “self-referential by pointer”; only the latter avoids infinite size problems.
Final Answer:Correct
Discussion & Comments