COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
22 bytes
|
|
10 bytes
|
|
14 bytes
|
|
18 bytes
|
Detailed explanation-1: -Since u is a union, memory allocated to u will be max of float y(4 bytes) and long z(8 bytes). So, total size will be 18 bytes (10 + 8).
Detailed explanation-2: -The total memory required to store a structure variable is equal to the sum of size of all the members.
Detailed explanation-3: -However, the size of uJob is 32 bytes. It’s because the size of a union variable will always be the size of its largest element. In the above example, the size of its largest element, ( name[32] ), is 32 bytes. With a union, all members share the same memory.
Detailed explanation-4: -Succinctly, the size of a union is the size of its largest element; the size of a structure is the sum of the sizes of its elements, plus padding where needed.