In C how much space does a bool (boolean) take up? Is it 1 bit, 1 byte or something else? Does it matter if the program is 32-bit or 64-bit?
If you are referring to C99 _Bool
try:
printf("%zu\n", sizeof(_Bool)); /* Typically 1. */
Note the standard says:
6.2.5
An object declared as type
_Bool
is large enough to store the values 0 and 1.
The size cannot be smaller than one byte. But it would be legal to be larger than one byte.
The smallest addressable "thing" in C is a char
. Every variable in C must have a unique address, therefore your bool
can't be smaller than that. (Note that char
isn't always 8 bits though)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With