#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
union A
{
int i;
char x[4];
} test;
int main()
{
cout<<"a[0] addr: "<<(int)&test.x[0]<<"\na[1] addr: "<<(int)&test.x[1]<<"\na[2] addr: "<<(int)&test.x[2]<<"\na[3] addr: "<<(int)&test.x[3]<<endl;
test.x[0]=0;
test.x[1]=1;
test.x[2]=2;
test.x[3]=3;
cout<<hex<<setw(11)<<test.i<<endl;
test.i=test.i>>4;//右移4位:这样的话,是不是左右移动相当麻烦?
cout<<setw(11)<<test.i<<endl;
cout<<"a[0]: "<<setw(5)<<(int)test.x[0]<<"\na[1]: "<<setw(5)<<(int)test.x[1]<<"\na[2]: "<<setw(5)<<(int)test.x[2]<<"\na[3]: "<<setw(5)<<(int)test.x[3]<<endl;
test.i=test.i>>4;//右移4位
cout<<setw(11)<<test.i<<endl;
cout<<"a[0]: "<<setw(5)<<(int)test.x[0]<<"\na[1]: "<<setw(5)<<(int)test.x[1]<<"\na[2]: "<<setw(5)<<(int)test.x[2]<<"\na[3]: "<<setw(5)<<(int)test.x[3]<<endl;
system("pause");
return 0;
}//int类型的内存模式
