Practice mode C#

What does Console.WriteLine(sizeof(char)); print in C#?

Correct answer B. 2

Explanation

A C# char is a UTF-16 code unit, so it occupies 2 bytes and sizeof(char) returns 2. This differs from C, where char is one byte. Characters outside the Basic Multilingual Plane, such as many emoji, need two chars (a surrogate pair). sizeof can be used on built-in unmanaged types like char and int without an unsafe context.

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.