Question 9: Struct and Union (8 pts) What is the size in bytes of the following
ID: 3881795 • Letter: Q
Question
Question 9: Struct and Union (8 pts) What is the size in bytes of the following data structures? a) Size of point3D struct point3D (2 pts) signed short x; unsigned int y; char *z; b) Size of val union val 2 pts) long long 11val; char str; short ival [2]; float fval; double dval c) Size of compound struct compound ( 2 pts) char mystring; long *y; union char *c short i; char f; ui d) Size of more compound(2 pts struct more_compound ( char name; int age; short pay; long height; union [ char short id short normal id; char my id; id; union char *text data; int *numeric data long *1_numeric_data; ) data;Explanation / Answer
Ans a.) 5 bytes
Because signed short x takes 2 bytes, unsigned int takes 4 bytes and character takes 4 bytes hence ,( 2+4+4) bytes=10 bytes
Ans b.) 8 bytes
because The largest member takes 8 bytes i.e long long llval;
Ans c.) 9 bytes
the union takes 4 bytes because of char *c i.e largest member
then struct is 1+4+4 = 9 bytes
Ans d.) 17 bytes
the 1st union takes 2 bytes because of largest member i.e short normal_id and the 2nd union takes 4 bytes because of its largest member i.e int *numeric_data;
then 1+4+2+4+2+4=17 bytes