刘嘉俊 魔王:共用体程序解释

来源:百度文库 编辑:高校问答 时间:2024/05/13 14:18:50
#include <iostream.h>
void main()
{
union{
int i;
char c[4];
}a;
cout<<"please input an integer:";
cin>>a.i;
cout<<endl;
for (int k=3;k>=0;k--)
cout<<(int)a.c[k]<<'\t';
cout<<endl;

结果
please input an integer:511

0 0 1 -1
*********************************
please input an integer:9221

0 0 36 5
***************************
不明白结果是怎么来的