Hi , Could you please explane why the size of the struct is 4 byte? Code: struct bitfield { int a:5; int c:5; int b:6; };
Your machine likely uses 32 bits for ints - to verify, you can multiply the macro CHAR_BIT by sizeof(int). Since the bitfield you've posted is comprised of 16 bits, it needs the space of 1 int or 4 bytes on your machine. You can test it by adding more Code: struct bitfield { int a:5; int c:5; int b:6; int d:16; int e:32; int f:4; }; a-d utilizes 32 bits, e utilizes 32 bits, and f utilizes 4 bits; the sizeof(bitfield) *should* require 12 bytes as space of 3 ints are needed.