为什么这个程序的输出是4
?
#include <iostream>
int main()
{
short A[] = {1, 2, 3, 4, 5, 6};
std::cout << *(short*)((char*)A + 7) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,在x86 little endian系统上,char有1个字节,短2个字节,输出应该是0x0500
,因为数组中的数据A
是十六进制的休闲:
01 00 02 00 03 00 04 00 05 00 06 00
Run Code Online (Sandbox Code Playgroud)
我们从开始向前移动7个字节,然后读取2个字节.我错过了什么?