首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请星星来解释下这段程序的运行结果什么是:120 86 52 18解决方案

2012-02-06 
请星星来解释下这段程序的运行结果什么是:120 86 52 18#includestdafx.h #includeiostream#includest

请星星来解释下这段程序的运行结果什么是:120 86 52 18
#include   "stdafx.h "
#include   <iostream>
#include   <string>
using   namespace   std;


void   main()
{

unsigned   int   finder   =   0x12345678;

unsigned   char   buff[4]   =   {0,0,15,1};

for   (int   i=0   ;i   <   sizeof(int)   ;i++)
{
unsigned   char   a   =   (((unsigned   char*)&finder)[i]);

cout   < <   (unsigned   int)a   < <   endl   ;

}


}

[解决办法]
little endian的机器上是78 56 34 12
big endian的机器上是12 34 56 78

当然,上面的数都是16进制,输出的时候会被转化为10进制
[解决办法]
cout < < std::hex < < (unsigned int)a < < endl ;
会让你看得清楚点。

热点排行