Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What will the int overflow become?
What will the int overflow become?
Int overflow becomes the difference between the overflow value and the maximum representable range value.

When the data size of an integer exceeds the representable range and the numerical range is not checked in the program, the output value of this integer variable will be disordered, which is not the expected running result.

When 1 is added to the maximum value, the result becomes the minimum value in the range; The maximum value plus 2, the result becomes the second smallest value in the range, which is the overflow of int data type. This situation will have a cycle.

Extended data:

If you want to avoid this situation, you must add a numeric range checker to your program, or use a larger data type to represent the range, such as long integer. You can add a capitalized "L" after any constant in the expression, or

Is to add long in front of the variable as a forced type conversion.

In a general computer, int occupies 4 bytes and 32 bits, and the data range is-2147483648 ~ 2147483647 [-231~ 231]. In the previous microcomputer, int occupied 2 bytes, 16 bits, and the data range was-32768 ~ 32767 [-215 ~ 215-1].