What is the size of the following Union ? Assume that the size of int = 2, size of float = 4, size of…
For the ordinary union-layout model of this 2013 size question, storage is shared among members and sized to the largest, the four-byte float. Thus B=4; 1 or 2 cannot…
Choose your answer
What is the size of the following Union ? Assume that the size of int = 2, size of float = 4, size of char = 1
union tag {
int a;
float b;
char c;
};Answer and explanation
Correct answer B
For the ordinary union-layout model of this 2013 size question, storage is shared among members and sized to the largest, the four-byte float. Thus B=4; 1 or 2 cannot contain float and 7 incorrectly adds all member sizes. Exotic extra aggregate padding is permitted by C but is not a competing layout model specified or suggested by these textbook assumptions.
Practice for these exams
-
UGC NET Computer Science and Applications