【发布时间】:2014-08-30 17:09:55
【问题描述】:
#include <stdio.h>
#include <string.h>
main()
{
short int x=0x55AA;
printf("%x ",~x);
}
上面的程序给出了输出:ffffaa55。我期待 o/p 只有 aa55,因为 short int 是 2 个字节。谁能解释一下?
【问题讨论】:
-
"%x "-->"%hx " -
@pat 哦,我以为 OP 会问为什么
~x和-x会产生不同的结果。我没有得到问题 - 我的错。 -
@Benjamin Gruenbaum
~x是 one's complement 的x..
标签: c integer-promotion