互联网公司面试题之七

问题:[color=red]编写一个程序来确定一下你的机器是大端地址还是小端地址[/color]。

答:实现代码如下:


#include <stdio.h>

int main(){
int value = 0x1234;
char value_front=*((char *)(&value));
char value_back=*((char *)(&value)+1);
printf("value_front=0x%x\nvalue_back=0x%x\n",value_front,value_back);
system("pause");
return 0;
}



运行结果:

[img]http://dl.iteye.com/upload/attachment/606227/243d9b64-5e37-3275-ab4e-60e374da6550.jpg[/img]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章