Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the overflow of int integers in C language?
What is the overflow of int integers in C language?
From the internal processing mechanism of C language, it is considered that the number of int is out of range (overflow) is a normal phenomenon, which will only produce wrong calculation results or logical errors and will not trigger the exception of data overflow. Therefore, in order to avoid program logic or calculation errors caused by integer overflow, programmers must detect possible overflow or ensure that data overflow does not occur.

There is only one simplest principle for C language to deal with the out-of-range data of int type: truncation, that is, the high-order bytes beyond the range of int bit length are automatically truncated.

For example, suppose the length of int is 16 bits, and the following code:

Internationalorganizations (same as international organizations)

a = 0X77FFFFL

/*

Because it is out of range, the high order 77 will be automatically truncated, and the actual a is equal to 0xFFFF.

*/

++ a;

/*

When a is increased, it will be out of range, and the higher order 1 will be truncated, and the actual A = 0.

*/