* Virtual_X:
Why bool type take 1 byte and as we know it must have only true or
false (1 or 0) that mean that it need only one bit not the a whole byte
A 'bool' is not guaranteed to have size 1 (1 byte).
Depending on the implementation it might have size 2, 4 or 8.
The standard allows any size for 'bool', so theoretically a 'bool' could
have size 4 GBytes, although that compiler would probably not sell very
well.
In the other direction, in C++ a 'bool' that is not a bitfield cannot
have size less than 1 (byte) because it must have an address, and the
smallest address increment is 1.
However, as a bitfield it can be just 1 bit if you want,
struct X
{
bool a : 1; // 1 bit
bool b : 2; // 2 bits
bool c : 5; // 5 bits
};
With at least one compiler this structure fits in one byte, that is, the
total size is 1 (byte). But note that you cannot apply sizeof to a
bitfield. From the sizeof perspective bitfields don't have sizes
because the sizeof granularity (resolution) is one byte, and C++ does
not offer any means of measuring sizes in terms of bits.
Cheers, & hth.,
- Alf