#include <iostream>
using namespace std;
struct X1
{
int i;//4个字节
char c1;//1个字节
char c2;//1个字节
};
struct X2
{
char c1;//1个字节
int i;//4个字节
char c2;//1个字节
};
struct X3
{
char c1;//1个字节
char c2;//1个字节
int i;//4个字节
};
int main()
{
cout<<"long "<<sizeof(long)<<"\n";
cout<<"float "<<sizeof(float)<<"\n";
cout<<"int "<<sizeof(int)<<"\n";
cout<<"char "<<sizeof(char)<<"\n";
X1 x1;
X2 x2;
X3 x3;
cout<<"x1 的大小 "<<sizeof(x1)<<"\n";
cout<<"x2 的大小 "<<sizeof(x2)<<"\n";
cout<<"x3 的大小 "<<sizeof(x3)<<"\n";
return 0;
}
内存对齐
最新推荐文章于 2024-07-22 00:52:41 发布