我有以下代码:
int main ( void ) {
unsigned int array [] = { 298 , 0 x1A2A3A4A };
unsigned char *p = ( unsigned char *) array ;
for (int i = 4; i < 8; i ++) {
printf ("% hhX ", p[i]) ;
}
printf ("\ nThe Answer is %d or %d!\n", p[0] , p [6]) ;
return EXIT_SUCCESS ;
}
我不明白输出:
4A 3A 2A 1A
The Answer is 42 or 42
最佳答案
在小端系统上,8字节的布局array
是
Position: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
Value (Hex): 2A | 01 | 00 | 00 | 4A | 3A | 2A | 1A
循环按照数组中出现的顺序打印最后 4 个字节。你的最后printf
打印 0 和 6 位置的值,均为 0x2A,即十进制的 42。
关于c - 无符号字符数组的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59236419/