#include <iostream>
using namespace std;
struct S
{
int a;
char b;
int c;
char d;
char e;
int f;
double g;
int h;
};
int main()
{
S s;
s.a = 10;
s.b = 'b';
s.c = 30;
s.d = 'd';
s.e = 'e';
s.f = 60;
s.g = 70.0;
s.h = 80;
cout<<sizeof(s)<<endl;
void* x = &s;
cout<<*(int*)x<<endl; //a
x = (int*)x+1;
cout<<*(char*)x<<endl; //b
x = (int*)x+1;
cout<<*(int*)x<<endl; //c
x = (int*)x+1;
cout<<*(char*)x<<endl; //d
x = (char*)x+1;
cout<<*(char*)x<<endl; //e
x = (char*)x+3;
cout<<*(int*)x<<endl; //f
x = (int*)x+1;
cout<<*(double*)x<<endl; //g
x = (double*)x+1;
cout<<*(int*)x<<endl; //h
return 0;
}
输出结果为:
32
10
b
30
d
e
60
70
80