From the perspective of the internal processing mechanism of the C language, int type numbers exceeding the range (overflow) are considered a normal phenomenon. They will only produce incorrect calculation results or logical errors, but will not trigger data overflow. abnormal. Therefore, in order to avoid program logic or calculation errors due to integer overflow, programmers must detect possible overflows themselves or ensure that data overflow does not occur.
C language has only one simplest principle for processing int type data out of range: truncation processing, that is, the high byte that exceeds the int bit length range is automatically truncated.
For example, assuming that the length of int is 16 bits, the following code:
int
a=0X77FFFFL;
/*
Due to exceeding the range, the high bit 77 will be automatically truncated, and the actual a will be equal to 0xFFFF
*/
++a;
/*
After a is incremented, it will exceed the range, the high 1 is truncated, and the actual a=0
*/