Size of structure

Struct {
int a : 8;
int b : 10;
int c : 12;
int d : 4;
int e : 3;
int : 0;
int f : 1;
char g;
} A;
what is the size of structure. size of bitfields with out character allocation is 48 bytes. so it is taking 4+4 =8 bytes. what about memory for character. Why memory for char is not allocated seperately. I am expecting size=4+4+1=9 bytes. When I compiled. it is giving 8 bytes. Can any one help me and clarify me.

  
Showing Answers 1 - 1 of 1 Answers

shailesh

  • Nov 22nd, 2018
 

Data alignment is different than checking the size, so please dont mingle these two concepts,Now 8+10+12+4+3=37 == 8Bytes gone(if int is of 4Bytes)its taking next boundary for int f and char g,caz int:0(which means goto next boundary location which is next 16 here.)So for f n g it takes more 4 bytes to reserved.Total Bytes are 12 for this structure.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions