Size of structure with bit fields
问题 Here I have a code snippet. #include <stdio.h> int main() { struct value { int bit1 : 1; int bit2 : 4; int bit3 : 4; } bit; printf("%d",sizeof(bit)); return 0; } I'm getting the output as 4 (32 bit compiler). Can anyone explain me how? Why is it not 1+ 4 + 4 = 9? I've never worked with bit fields before so would love some help. Thank you. :) 回答1: When you tell the C compiler this: int bit1 : 1 It interprets it as, and allocates to it, an integer; but refers to it's first bit as bit1 . So if