如何获得300的输出?从这段代码? [英] How do I get output of 300? From this code?
本文介绍了如何获得300的输出?从这段代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
main()
{
short int x;
unsigned char *p=&x;
*p=44; //write 44 into first byte x
*(p+1)=1; //write 1 into second byte of x
printf("%d:,x);
}
我尝试了什么:
我无法理解输出是如何300的。
What I have tried:
I didn't able to understand that how the output is 300.
推荐答案
因为您的架构是 little endian [ ^ ]。
使用指针在44 ,在地址x'+ 1处存储 1
然后x
(两个字节的整数)的值是1 * 256 + 44 = 300
。
Because your architecture is little endian[^].
Using the pointer you store44
at 'address of x' and1
at address of x' + 1. Hence the value ofx
(a two byte integer) is then1 * 256 + 44 = 300
.
这篇关于如何获得300的输出?从这段代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文