Difficulty: Easy
Correct Answer: 20
Explanation:
Introduction / Context:
Unions in C overlay their members in the same memory location, so writing to one member overwrites the storage seen by the others. This question tests that understanding.
Given Data / Assumptions:
Concept / Approach:
The last write into the union’s shared storage sets the bits seen by all members. After writing v.b = 20, both a and b see the same bit pattern, which corresponds to 20 when interpreted as int.
Step-by-Step Solution:
Verification / Alternative check:
Printing v.b immediately after would also show 20, confirming the shared memory behavior of unions.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming unions keep independent values like structs; they do not. Only the most recent write is represented in shared storage.
Final Answer:
20
Discussion & Comments