Structures & Declarations
![Question 1.17, GATE 2000: A structure contains short s[5] and a union holding either float y or long z. short,float,long occupy 2,4,8 bytes. Ignoring alignment, choose size 22,14,18,10 bytes.](../../assets/questions/CS-2000-Q17-1.webp)
![Question 1.17, GATE 2000: A structure contains short s[5] and a union holding either float y or long z. short,float,long occupy 2,4,8 bytes. Ignoring alignment, choose size 22,14,18,10 bytes.](../../assets/questions/CS-2000-Q17-2.webp)
Your answer
Answer & solution
Answer: C (no official key was published)
Step 1: The array has five separate short objects, requiring 5·2=10 bytes.
Step 2: Union members share storage, so the union needs the maximum of 4 and 8 bytes, namely 8, rather than their sum. The enclosing structure stores its array and union separately.
Total size ignoring padding is 10+8=18 bytes, C. Adding both union members would incorrectly give 22; actual ABI alignment could add padding, explicitly excluded here.