1c++_union.cpp
#include<iostream>
using namespace std;
//union是联合体,其所在空间是其内部最大元素的空间大小 ,换句话说,其内部所有成员的空间是共用的
union A{
int a=0x30313233;
char s[4];
};
int main()
{
// cout<<sizeof(A)<<endl;
A a;
cout<<hex<<"a.a=0x"<<a.a<<dec<<endl;
cout<<"a.s[0]=0x"<<hex<<(int)a.s[0]<<endl;
char ch=(int)0x12345678;
cout<<"ch=0x"<<(int)ch<<endl;
int m=0x12345678;
char *pch =(char*)&m;
cout<<"*pch=0x"<<(int)*pch<<endl;
}