0

With the below code:

struct S {
unsigned char b1 : 3;
int i;
};

I can deduce that char b1 is of 1 byte and using 3 bits of that and int is 4 bytes but when I try to print out the size of S, I get it 8 bytes instead of 5 bytes(1 for char+4 for int) as I expected and this is something I am not understanding by obvious. Can something explain why size of S is 8 bytes?

3
  • 2
    stackoverflow.com/questions/6968468/… Commented Apr 19, 2016 at 4:36
  • run this code on vc++ and gcc compiler and result is same. Commented Apr 19, 2016 at 4:37
  • 1
    And the reason is the same too. Have you read the link? Or this one? Or this? Commented Apr 19, 2016 at 4:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.