unsigned x = 0 ; unsigned newx = x -1; if (newx > x)
- actually if you got the number from SCANF or CIN you cant know the "original" number so i guess that you cant detect that over / under flow
Not actually what if the overflow or underflow causes the number to be larger or higher than the reference?
IT CAN BE IN ONLY A FEW CASES THAT YOU CAN PREDICT
Imagine this... uint x = 123; x += UNSIGNED_INT_MAX; and x will still be 123 even though it overflowed
The C++ standard specifies that any unsigned integer that overflows acts like number % (UINT_MAX + 1). Its completely assured when you overflow you start over from 0 with the remainder.
Обсуждают сегодня