Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Give the minimum size of each of the following C++ types. char has1 byte, short

ID: 3614662 • Letter: G

Question

Give the minimum size of each of the following C++ types. char has1 byte, short has 2 bytes, int & float has 4 bytes, double& long has 8 bytes, pointer has 4 bytes.
a) struct sl_type { long i; char ch; int *ip; };
b) union u_type { float f; char *cp; short s[3]; double d; };
c) struct s2_type { u_type u; float *fp; long n; char c[15]; sl_type t;
};


a) struct sl_type { long i; char ch; int *ip; };
b) union u_type { float f; char *cp; short s[3]; double d; };
c) struct s2_type { u_type u; float *fp; long n; char c[15]; sl_type t;
};

Explanation / Answer


a) struct sl_type { longi;                               8 bytes
charch;                       +   1
int*ip;                         +   4
};                                   13 bytes

b) union u_type { floatf;                                4 bytes
char*cp;                         +4
shorts[3];             +2(3)= 6
doubled;                           8
};                                     22 bytes

c) struct s2_type { u_typeu;                     22 bytes
float*fp;                 +    4
longn;                      + 8   
charc[15];               + 15
sl_typet;                  + 13
                                   62 bytes
};
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote