In almost every C++ implementation you'll come across, a char
is exactly a byte
an octet. This is not guaranteed by the C++ standard, but it's practically always the case. A char
is always at least 8 bits large, and the exact number of bits is given by the preprocessor constant CHAR_BIT
. Also, the sizeof()
operator tells you the size of an object/type in terms of the number of char
s, not the number of bytes octets, so if you were on some weird system with a 16-bit char
and a 32-bit int
, then sizeof(int)
would be 2, not 4.
EDIT: Replaced byte by octet. A char
is guaranteed to be a byte by the C standard, but a byte is not guaranteed to be an octet, which is exactly 8 bits. If you've ever read any French technical literature, they always use 'octet' instead of 'byte', and they have kilooctets (KO), megaoctets (MO), etc. instead of kilbytes and megabytes.