int main(void)
{
printf("hello word\n");
int i = -2147483648;
printf("%d, %d, %d, %d\n", ~ i, -i, 1-i, -1-i);
return 0;
}
求结果
vs2019,x64编译报错
int main(void)
{
printf("hello word\n");
int i = -2147483647;
printf("%d, %d, %d, %d\n", ~ i, -i, 1-i, -1-i);
return 0;
}
//结果为:hello word
2147483646,2147483647,-2147483648,2147483646
//结果为:hello word
2147483646,2147483647,-2147483648,2147483646
解析:负数采用补码表示,为取反加1