linear-cpp
linear-cpp copied to clipboard
What is a char?
With the proliferation (if I think of a word that sounds more like how a disease spreads, I'll edit this) of unicode, it's become pretty common for new languages to make allowances for unicode strings, or to use unicode strings natively. In both cases, a character is a pretty strange type--and often we're talking about something that is 16 or 32 bits wide. This isn't the case in C++. I actually don't know off the top of my head what a character in C++ is (I think it's an 8-bit value representing... ascii?), so I think that (for experienced programmers, anyway) it might be good to mention that in passing.
A char is a byte -- that is, 8 bit. However, by way of ASCII, "character" did, in fact, inspire the naming of "char."
The more important point of confusion is the size of int / uint, because they are only defined as at least values, leaving compilers with the freedom to determine the sizes at will. (i.e. int can be 4 bytes, but also 2 bytes; sometimes it's also a 64bit value -- 8 bytes. That way you are nearly always forced to determine sizes using sizeof.)