c++,内存对齐的原理和测试

tech2025-06-16  2

点击阅读原文

#include<iostream> #pragma pack(4)//4的倍数 using namespace std; int main(){ struct a{ char i; int j; }c; cout<<sizeof(c)<<endl;//8 } //32位系统 #include<stdio.h> struct { int i; char c1; char c2; }x1; struct{ char c1; int i; char c2; }x2; struct{ char c1; char c2; int i; }x3; int main() { printf("%d\n",sizeof(x1)); // 输出8 printf("%d\n",sizeof(x2)); // 输出12 printf("%d\n",sizeof(x3)); // 输出8 return 0; }

最新回复(0)