写出sizeof(struct name2)的结果
struct name2{
char str;
int num;
short x;
}
写出sizeof(struct name1) 的结果
struct name1{
char str;
short x;
int num;
}
地址对齐不太会,求指教!
写出sizeof(struct name2)的结果
struct name2{
char str;
int num;
short x;
}
写出sizeof(struct name1) 的结果
struct name1{
char str;
short x;
int num;
}
地址对齐不太会,求指教!
取决于对齐大小,比如缺省4字节对齐
struct name2{
char str; // 因为num要4字节,str本身1字节,但是为了对齐,所以占用4字节
int num; // 4字节
short x; // 同样,x本身2字节,占用4字节
}
4 + 4 + 4 = 12
struct name1{
char str; //占用1个字节
short x; // 占用后两个字节,为了对齐,填充1个字节
int num; //4字节
}
1+2+1+4 = 8