1. 结构体的回顾
1.1 结构体的对齐原则
struct student{
short num;
char name[20];
char age;
float score;
};
- 各成员位置:
num:[0,2)
name:
对齐数=min(sizeof(char),8)=1,占用1的整数倍2
[2,22)
age:
[22,23)
score:
对齐数=min(sizeof(float),8)=4,占用4的整数倍24
[24,28)
- 结构体大小
最大对齐数=max(2,1,4)=4,为最大对齐数的整数倍,即28