INT_MAX and INT_MIN considerations

[ACM] Notes for INT_MAX and INT_MIN

INT_MIN is defined in the standard header file limits.h.

#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX - 1)12

In C/C++ language, -2147483648 cannot be used directly instead of the smallest negative number, because this is not a number, but an expression. The expression means to negative the integer 21473648, but 2147483648 has overflowed the upper limit of int, so it is defined as (-INT_MAX -1).

The int type in C is 32 bits, and the range is -2147483648 to 2147483647.
(1) The slightest overflow is INT_MAX + 1: the result is INT_MIN;
(2) The most serious overflow is INT_MAX + INT_MAX: the result is -2;
(3) The slightest underflow is INT_MIN-1: the result is It is INT_MAX;
(4) The most serious underflow is INT_MIN + INT_MIN: the result is 0.

Guess you like

Origin blog.csdn.net/qq_31433709/article/details/109034202