コード:
int main()
{
unsigned int a = 0xfffffff7;
char *b = (char *)&a;
printf("%08x",*b);
}
出力は次のとおりfffffff7です。私のマシンはリトルエンディアンです。もちろん*bequals0xf7は知っていますが、なぜ の出力がprintf()このようになるのかはわかりません。
コード:
int main()
{
unsigned int a = 0xfffffff7;
char *b = (char *)&a;
printf("%08x",*b);
}
出力は次のとおりfffffff7です。私のマシンはリトルエンディアンです。もちろん*bequals0xf7は知っていますが、なぜ の出力がprintf()このようになるのかはわかりません。
Since your system is small-endian, a is stored in memory as F7 FF FF FF.
b points to the first byte of a. (F7)
*b evaluates to a char. (F7)
*b is promoted to an int in order to pass it as a parameter, since it's of type char (which usually defaults to signed char) it is sign-extended to become FFFFFFF7.