Four-byte alignment
1 typedef struct user USER; 2 typedef struct employee E; 3 struct user{ 4 5 char name[10]; //take 12 bytes 6 int age; //take 4 bytes 7 short sex;//take 4 bytes 8 char blood;//take 1 bytes but in the 4 bytes of sex 9 }; 10 struct employee{ 11 12 char name[5]; //take 8 bytes 13 int age; //take 4 bytes 14 char blood;//take 4 bytes 15 }; 16 int main(){ 17 18 printf("%d\n", sizeof(USER));// 12+4+4 19 printf("%d\n", sizeof(E));// 8+4+4 20 system("pause"); 21 }
时间: 2024-10-27 07:21:35