Reputation: 19
If a char
is a small integer, why can it contain symbols?
Upvotes: 0
Views: 128
Reputation: 874
char
is a single byte integer, which means at least 256 possibilities (assuming the compiler follows the c standard). The lower 128 (number 0-127 inclusive) include almost all "symbols" you see printed. Here's a list: https://www.asciitable.com/
This often does not include more complicated characters, commonly called "multi-byte characters" which consist of more then 8 bits, such as emojis and eastern Asian word-characters. Different systems have different ways of handling these, but very few use the char
type in C for more then one byte characters.
As a general rule, treat a char
/byte like it is exactly 8 bits. Though some systems may allow char
to be bigger, that's not always the case. Use the platform-specific type for multi-byte characters if you want to use them.
Upvotes: 1