Question

C Programming Given the declarations: struct STRUCTURE { int aa[7]; double dd; char ff[30]; } union...

C Programming

Given the declarations:
struct STRUCTURE
{
int aa[7];
double dd;
char ff[30];
}
union Group
{
char bb[7];
int a[7];
}
struct STRUCTURE yy;
union Group zz;

(you may assume that sizeof(char)=1; sizeof(int)=4; sizeof(double)=8;

Number of bytes reserved for yy is

Number of bytes reserved for zz is

Homework Answers

Answer #1

The memory is read in a block, and a block is of 8 bytes. When the variables are assigned and the memory is allocated, the memory allocation is done in such a way that 8 bytes are always read at a time. Hence the compiler leaves some useless space so that the provided variables can be fully fitted in a block size(i.e 8 bytes).
Hence the memory allocation will be
For int aa[7] = 7*4= 28 = 32(leaving some extra bytes to maintain block read write)
dd = 8
And ff = 30 = 32 (leaving some extra bytes to maintain block read write)

Hence total = 32+8+32 = 72 This is called structure padding. Therefore size of yy=72

For union, the total memory size of the union = size of biggest data variable, in this case it is int a[7] = 7*4 = 28 bytes. Therefore size of zz=28 bytes.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT