0
点赞
收藏
分享

微信扫一扫

union内存空间


union {
int a;
char p[5];
char*a;
}UNION;
int *a;
cout << sizeof(UNION) << endl;
cout << sizeof(a) << endl;

union内存空间由大括号中占内存最大的决定,上述代码中char数组内存空间最大为5,但是int类型,需要与对齐,那就是变成8了 

举报

相关推荐

0 条评论