Practice mode C#

What is the output of: byte b = 255; b++; Console.WriteLine(b);?

Correct answer A. 0

Explanation

The increment operator on a byte performs the addition and converts back to byte implicitly. In the default unchecked context, 256 does not fit in 0 to 255, so the value wraps to 0. Note that b = b + 1; would not compile without a cast, because b + 1 is an int, but b++ and b += 1 include the conversion automatically.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.