Size of char

Hi :)
Is is true that char has a different size depending on computer? If yes, could you say, why?

(sry for bad eng, i'm not native English)
It is defined, in C++, as being the size of a single addressable lump of memory. By definition, one byte. sizeof(char) will always be one.

However, the size of a byte (i.e. how many bits it contains) is not the same across all systems everywhere. Thanks to various parts of the C++ standard, a char in C++ must be at least 8 bits, but could be larger.

You can read about it here: https://isocpp.org/wiki/faq/intrinsic-types#sizeof-char

All that said, if you're using fairly standard x86 and x64 systems, you don't have to worry about unusual byte sizes.
Last edited on
In the event that you are on some very unique hardware*, you can use CHAR_BIT defined in <climits> to know how many bits are in a char on your platform.

* https://stackoverflow.com/questions/5516044/system-where-1-byte-8-bit
Last edited on
Registered users can post here. Sign in or register to post.