I am learning C++. In todays lesson I came to know that a boolean variable takes a total byte. Why? A Boolean evaluates to either true or false and a single bit is enough for storing 1 for true and 0 for false. What it does with those extra 7 bits?
Asked
Active
Viewed 121 times
0
-
1It's just that you can't allocate less than one word of memory. – Sam Jul 12 '15 at 06:59
-
1and even if the compiler was to combine the booleans into a bitfield, it would not allow you to get a pointer to your boolean. or get the sizeof() your boolean. bitfields would work in other languages where this detail is hidden. but not in C++ where & and sizeof() etc are requirements on types. – slipperyseal Jul 12 '15 at 07:17
-
@deviantfan my mistake, thanks for the correction. – Sam Jul 12 '15 at 07:26