give the minimum size of each of the following C types assum

give the minimum size of each of the following C++ types, assumming that char 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.

3. Give the minimum size of each of the following C++ es, assuming that char 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. (a) union u type double a [2]; int *b char c [16] (b) struct s1 type float *d [2] long e C4 char f [8]; short *g; (c) struct s2 type f s1 type s; u type u [2]; int [5] short i double j;

Solution

a)

union u_type
{
   double a[2];
   int *b;
   char c[16];
};

16 bytes

The size of the union is the largest data type. here double a[2] requires 8*2 = 16 bytes,b requires 4 bytes and char c[16] also requires 16 bytes. So size of union is 16 bytes.

b)

struct s1_type
{
   float *d[2]; // 4*2 = 8 bytes
   long e[4]; // 8*4 = 32 bytes
   char f[8]; // 1*8 = 8 bytes
   short *g; // 4 bytes
};

size of the structure = (8+32+8+4) = 52 bytes

c)

struct s2_type

{

s1_type s; //52 bytes

u_type u[2]; //16*2 bytes = 32 bytes

int *h[5]; //4*5 bytes = 20

short i; //2 bytes

double *j; //4 bytes

};

size of the structure = (52 +32 +20 + 2+ 4) = 110 bytes

give the minimum size of each of the following C++ types, assumming that char values occupy one byte, short values occupy two bytes, int and float values occupy

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site