#include <stdio.h>
union
{
int i;
char x[2];
}a;
void main()
{
a.x[0] =10;
a.x[1] =1;
printf("%d",a.i);
}
main()
{
union{ /*定义一个联合*/
int i;
struct{ /*在联合中定义一个结构*/
char first;
char second;
}half;
}number;
number.i=0x4241; /*联合成员赋值*/
printf("%c%c\n", number.half.first, mumber.half.second);
number.half.first='a'; /*联合中结构成员赋值*/
number.half.second='b';
printf("%x\n",number.i);
getch();
}
看看一些,程序