Why may an overflow occur in the following program?
问题 void main () { int i; if (i < 0) { i = -i; }; } Can anyone help me to understand why an overflow may occur in the above program? 回答1: An overflow may occur because the range of integer representation in two's complement is not symmetric: the magnitude of the smallest negative number that can be represented is the magnitude of the highest positive number that can be represented, plus one. For example, on a 32-bit system the values are -2,147,483,648 and 2,147,483,647 . That's why negating -2