What is the output of: int m = int.MaxValue; m++; Console.WriteLine(m); (default project settings)?
Correct answer B. -2147483648
Explanation
By default, non-constant integer arithmetic in C# runs in an unchecked context, so overflow silently wraps around using two's complement. Adding 1 to int.MaxValue (2,147,483,647) gives int.MinValue, -2,147,483,648. To make overflow throw OverflowException, wrap the expression in checked or enable the CheckForOverflowUnderflow compiler option. Constant expressions that overflow are compile-time errors instead.
Answer checked How we write and check questions
Discussion