sizeof struct with union [duplicate]
问题 This question already has answers here : How is the size of a C++ class determined? (4 answers) Closed 5 years ago . I'm very confused by the whole 'data alignment' thing: #include <stdio.h> int main(){ struct st{ int i,*p; char c; union { char type[4]; unsigned char d;} un; }; struct st s1={25,&a,'X',"asdf"}; printf("sizeof s1 is %d",sizeof(s1)); return 0; } due to data alignment, i thought that since the sizes of int i : 4 bytes int *p : 8 bytes char c : 1 byte(+3) union : 4 bytes the