lenelex.com
Home
Quizzes
Games
Register
Log in
Question 1 of 8
How many times will the loop body execute?
try { byte n = byte.MaxValue; while (n <= byte.MaxValue) { unchecked { ++n; } } } catch (Exception ex) { Console.Write(ex.GetType().Name); }
A. 255
B. 0
C. 1
D. Infinite
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.
Prefix increment operation
The result of prefix increment operation is the value of the operand after it has been incremented.
Infinite loop
Infinite loop (or endless loop) is a sequence of instructions which loops endlessly, either due to the loop having no terminating condition or having one that can never be met.
Links:
The while Statement
The Increment Operator (++)
The Unchecked Keyword