struct student{
9 char score[20];
10 int snum[10];
11
12 }stu;
13 int main()
14 {
15 printf("%d\n",sizeof(stu));
16 }
像这样算出来结果是60,如果在第11行加 char u[10]; 结果算出来是72,这是为什么呢?
struct student{
9 char score[20];
10 int snum[10];
11
12 }stu;
13 int main()
14 {
15 printf("%d\n",sizeof(stu));
16 }
像这样算出来结果是60,如果在第11行加 char u[10]; 结果算出来是72,这是为什么呢?
编译器会自动填充字节以对齐结构体元素内存位置。
深入学习可以参考:
http://www.cnblogs.com/clover-toeic/p/3853132.html
如果想禁止编译器的这种行为:
对visual studio来说,可以在文件头部加上:
# pragma pack (1)
如果有帮助,请采纳答案好吗,谢谢!