Example for bit fields in structures in c:
What is the output of below C program?
assume that int size in this system is 4 bytes.
printf("%d", sizeof(struct EmpStatus));
Once we allocate at least one bit field, it starts taking up entire int sized byte that is 4 bytes. it is upto the programmer if he wanted to use remaining bits in that entire 4 bytes or not. so it prints 4 (bytes). Note: as of now in this program we have used only 2 bits of 4 bytes(32 bits) so still 30 bits are left empty. so if we want we can use them as well for some other bit fields.
Back To Top