#include <iostream>
using namespace std;
int main(void)
{
struct test2
{
char a:2;
char b:2;
int c:2;
char d:2;
}t2;
memset(&t2, 0, sizeof(t2));
t2.a = 3;
t2.b = 2;
t2.c = 3;
t2.d = 3;
char *p = (char*)&t2;
//每个字节的地址和存储的值。
for (int i = 0; i < sizeof(t2); i++)
{
cout << "address:" << hex << (int)(p+i) << " ";
cout << "value:" << dec << (int*)*(p+i) << endl;
}
cout << sizeof(t2) << endl;
system("pause");
return 0;
}
address:12ff54 value:0000000B
address:12ff55 value:00000000
address:12ff56 value:00000000
address:12ff57 value:00000000
address:12ff58 value:00000003
address:12ff59 value:00000000
address:12ff5a value:00000000
address:12ff5b value:00000000
address:12ff5c value:00000003
address:12ff5d value:00000000
address:12ff5e value:00000000
address:12ff5f value:00000000
12