任何人都可以向我解释为什么这段代码打印“错误”?这只出现在整数的最小值上。溢出C代码
int abs(int x) {
int result = 0;
if(x < 0)
result = -1*x;
else
result = x;
return result;
}
int main() {
printf("Testing abs... ");
if (abs(-2147483648) != 2147483648)
printf("error\n");
else
printf("success\n");
}
你试图'INT A = -2147483648; int b = 2147483648; printf(“%d%d”,a,b);'? – 2012-02-18 00:29:25