#include <stdio.h> //结构体的大小,内存对齐 struct A { char a;//1+1 short b;//2 int c;//4 };//8 struct B { char a;//1+3 int b;//4 short c;//2 };//10+2 struct C { int a;//4 struct CC { char b;//1+3 int c;//4 }d;//4 };//12 单个最大的类型 struct D { int a;//8 double b;//12 };//16 int main() { printf ("A所占用的内存:%d\n",sizeof(struct A)); printf ("B所占用的内存:%d\n",sizeof(struct B)); printf ("C所占用的内存:%d\n",sizeof(struct C)); printf ("D所占用的内存:%d\n",sizeof(struct D)); return 0; }
【C语言】关于结构体的内存对齐
猜你喜欢
转载自blog.csdn.net/weixin_41576955/article/details/80210019
今日推荐
周排行