注册 登录
编程论坛 C++教室

有人能否帮我解释一下这个程序的运行结果?谢谢~~~~

莫一阳 发布于 2011-06-21 21:54, 388 次点击

#include<iostream>
using namespace std;

union u_type
{
    int num;
    char ch[2];
    void set_num(int anint);
    void showchars();
};

void u_type::set_num(int anint)
{
    num=anint;
}

void u_type::showchars()
{
    cout<<ch[0]<<' '<<ch[1]<<endl;
}

int main()
{
    u_type aunion;
    aunion.set_num(9798);
    aunion.showchars();
    return 0;
}

运行结果:
       F &
2 回复
#2
玩出来的代码2011-06-21 23:45
也是大小端问题了、intel的CPU大端模式,高位存放在高地址,低位在低地址、看ascii表、对应的 F &对应的数值。
#3
try_catch2011-06-22 03:26
楼上正解
1