内存对齐

// sizeof(char *) = 8
// sizeof(int) = 4

// sizeof(struct Person) = 16
// 8(name)
// 4(age) + 4(age) 
struct Person
{
    char *name;
    int age;
    int height;
};

// sizeof(struct Student) = 24
// 8(name)
// 4(age) + 4(age) 
// 4(weight) + 4(empty)
struct Student
{
    char *name; 
    int age; 
    int height;
    int weight;
};

你可能感兴趣的:(内存对齐)