From MSDN:
The Int32 value type represents signed integers with values ranging from
negative 2,147,483,648 through positive 2,147,483,647.
By default the int operations are not checked by overflow, for performance
reasons, you can set flag and the compiler will generate code to check that
it does not happen, it will throw an exception in that case.
1) 2147483647 + 2147483647 stored in a signed 32-bit location overflows the
positive range, and results in a wrapped value which is -2 in this case.
Research integer overflow for more & complete details.
in addition, if you want overflowexception, you can either specify the
compiler flag csc /checked+, or use 'checked' keyword in your code, which
will generate the exception.
1) 2147483647 + 2147483647 stored in a signed 32-bit location overflows
the positive range, and results in a wrapped value which is -2 in this
case. Research integer overflow for more & complete details.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.