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

Discussion

A char variable can store either an ASCII character or a Unicode character.

  • A.True
  • B.False

Answer: A

Correct answer: False

In C a char is one byte - sizeof(char) is 1 by definition - and on ordinary implementations that is eight bits, giving 256 possible values. That is ample for ASCII, which uses only the codes 0 to 127, but Unicode defines over a million code points, so a single char cannot hold an arbitrary Unicode character. C provides other types for that work: wchar_t for wide characters, and since C11 char16_t and char32_t for UTF-16 and UTF-32 code units, declared in <uchar.h>. What a char array can hold is a Unicode character encoded in UTF-8, but that takes one to four char elements per character, not one - the character is spread across several bytes rather than stored in a single variable. The confusion usually comes from Java, where char is a 16-bit UTF-16 code unit and the statement would be much closer to true. In C it is false.

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

Post your comment

Please log in or register to post a comment.