c / c++内存对齐

typedef struct Student_tag
{
 bool sex;
 char name[5];
} Student;

sizeof(Student)=6

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

typedef struct Student_tag
{
 bool sex;
 char name[5];
 uint8_t age;
 double score_1;    //sizeof(double)=8
} Student;

sizeof(Student)=16 (必须是8的整数倍)

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

typedef struct Student_tag
{
 bool sex;
 char name[5];
 uint8_t age;
 double score_1;
 unsigned int score_2;
} Student;

sizeof(Student)=24

猜你喜欢

转载自blog.csdn.net/chengde6896383/article/details/81085196