Size of booleans | Sololearn: Learn to code for FREE!


Size of booleans

According to the sizeof(); table in the lesson, a boolean allocates 1 byte but since a boolean can only hold 0 or 1, wouldnt it htake up a bit?

12/30/2016 5:55:29 AM


4 Answers

New Answer


In general, no data type will be a single bit because it is inconvenient to allocate and deal with less than a byte. If you are storing a lot of booleans, than you could pack up to 8 of them into a byte using something called bitfields, or even use bitwise operations to store them in integers, but you can't simply use a bit of storage by itself.


CPUs consider a byte as a smallest addressable unit.


Since 1 byte consists of 8 bits, 0 & 1can be written in terms of bytes like this 00000000 and 00000001 respectively.


the "1" is for us but for the computer it is "00110001"