Please let me know if you need more time. Thank you. Give the minimum size of th
ID: 653512 • Letter: P
Question
Please let me know if you need more time. Thank you.
Give the minimum size of the following C++ structure, assuming that char and bool values occupy one byte, short values occupy two bytes, int and float values occupy four bytes, double and long values occupy eight bytes, and pointers occupy four bytes. Struct s { float *a; Char b[2]; Union { double *c; int d; Short e; }; bool f: long *g[4]; }; Assuming that the structure has its minimum size, what is the offset of each member from the beginning of the structure? (The offset of a will be 0, for example.) Include the offsets of c, d, and e in your answer.Explanation / Answer
1)
as float takes 4 bytes
char b[2]=2 bytes
double *c 4 bytes
int d takes 4 bytes
short e takes 2 bytes
bool f takes 1 byte
long *g[4] takes 8x4=32 bytes
so 4+2+4+4+2+1+32 = 49 bytes
2)given offset a will be 0.
then for c=3 and for d=5,and e=6
OR we can calculate offset by method offsetof(S, c/d/e);