INT_MAX + 1 = INT_MIN in integers?

for (i = 0; i <= N; ++i) { ... }

This particular operator will cause an infinite loop if N is equal INT_MAX. It is known that Unsigned Overflows are overflows the assumption iand Nfor unsigned, the compiler can be assumed that the loop will iterate exactly N+1once, if ithere is an overflow undefined. The following should be noted here: if I create loops like,

for (i = 0; i < N; ++i) { ... }

Will it still be undefined behav?

Why is it INT_MAX + 1not necessarily equal INT_MINin the case of signed integers?

0
source share
2 answers

INT_MAX + 1

this operation causes undefined behavior. Signed integer overflow is undefined behavior in C.

INT_MIN, . .

+5
Why INT_MAX + 1 is not surely equal to INT_MIN in case of signed integers? 

-, undefined C. , , , , .

-, C . , . () , , . .

undefined - , , . undefined, .

+2

Source: https://habr.com/ru/post/1684944/


All Articles