#include#include struct Stu{ char c; int i; double d; short s;};int main(void){ struct Stu st; printf("%u,%u\n", sizeof(struct Stu),sizeof(st)); system("pause"); return 0;}
结果为24???
1+4+8+2=15啊?
原因为
1.以最大类型为字节对齐宽度
2.依次填补各个成员字节
3.结尾对齐
#include#include struct Stu{ char c; short s; int i; double d; };int main(void){ struct Stu st; printf("%u,%u\n", sizeof(struct Stu),sizeof(st)); system("pause"); return 0;}
结果为16?!!!!!