C语言unoin用法

union
{
    short int i;
    char x[2];
}a;
void main()
{
    cout << sizeof(a) << endl;
    //自然顺序3210
    a.x[1] = 0x11; a.x[0] = 0x00;
    printf("%x\n", a.i);

    a.i = 0x1100;
    printf("%x\n", a.x[1]);

    system("pause");
}

 

posted @ 2018-08-29 09:19  aote369  阅读(261)  评论(0编辑  收藏  举报