内存对齐和顺序是有关的
@1:内存对齐和顺序是有关的
#1
#include <iostream>
using namespace std;
class B
{
double f;
char p;
int a[3];
};
int main(void)
{
//cout << sizeof(char) << "\t" << sizeof(short) << "\t" << sizeof(double) << "\t" << sizeof(int) << "\t" << sizeof(float)<< endl; //1 2 8 4 4
cout << sizeof(B) << endl;
int a;
cin >> a;
return 0;
}
结果为24
#2
#include <iostream>
using namespace std;
class B
{
char p;
double f;
int a[3];
};
int main(void)
{
//cout << sizeof(char) << "\t" << sizeof(short) << "\t" << sizeof(double) << "\t" << sizeof(int) << "\t" << sizeof(float)<< endl; //1 2 8 4 4
cout << sizeof(B) << endl;
int a;
cin >> a;
return 0;
}
结果为32