Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the numerical range of a char?

  • A.-128 to 127
  • B.-(215) to (215) - 1
  • C.0 to 32767
  • D.0 to 65535

Answer: D

Correct answer: 0 to 65535

A char is a 16-bit *unsigned* integral type, so it spans 0 to \( 2^{16}-1 = 65535 \) - the full range of UTF-16 code units. It is the only unsigned type in Java, which is why a char used in arithmetic promotes to int and why casting a negative int to char produces a large positive value rather than a negative one. The signed 16-bit range offered belongs to short.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.