微软一面试题-----字节对齐
wbgxx 2010-05-13 12:59:14 #include <iostream>
using namespace std;
#pragma pack(8)
struct example1
{
short a;
long b;
};
struct example2
{
char c;
example1 struct1;
short e;
};
#pragma pack()
int main()
{
example2 struct2;
cout << sizeof(example1) << endl; //8
cout << sizeof(example2) << endl; //16
cout << (unsigned int)(&struct2.struct1) - (unsigned int)(&struct2)
<< endl; //这里为啥是4啊???能详细说说吗?????、
getchar();
}