我在一个网站上对 C 进行练习测试,我碰巧看到了这个问题。我的疑问在评论中有解释,所以请阅读它们。
#include<stdio.h>
int main()
{
int arr[3] = {2, 3, 4}; // its assumed to be stored in little-endian i.e;
// 2 = 00000010 00000000 00000000 00000000
// 3 = 00000011 00000000 00000000 00000000
// 4 = 00000100 00000000 00000000 00000000
char *p;
p = arr;
p = (char*)((int*)(p));
printf("%d ", *p);
p = (int*)(p+1); // This casting is expected to convert char pointer p
// to an int pointer , thus value at p ,now is assumed
// to be equal to 00000000 00000000 00000000 00000011
// but, the output was : 0 . As ,per my assumption it
// should be : 2^24+2^25 = 50331648 ,Please Clarify
// if my assumption is Wrong and explain Why?
printf("%d\n", *p);
return 0;
}