lenelex.com
Home
Quizzes
Games
Register
Log in
Question 1 of 8
What will be the output of the following code?
try { byte n = byte.MaxValue; unchecked { Console.Write(++n); } } catch (Exception ex) { Console.Write(ex.GetType().Name); }
A. 0
B. 255
C. OverflowException
D. 256
Default overflow-checking
By default, non-constant integral-type arithmetic expressions are not checked for overflow at run time. When incrementing the variable beyond the maximum limit, its value overflows and restarts at the type's minimum value.
Links:
The Unchecked Keyword
The Increment Operator (++)