0

How many bit(s) does a boolean variable contain? I remember it's 1. Correct me if I'm wrong...

1st Nov 2016, 9:00 PM
jiapei100
jiapei100 - avatar
3 Respostas
+ 2
As a boolean variable contains either a "0" or "1", it is easily stored in a single bit but the smallest unit to store any value in computer is 1 Byte(=8 bits). So, it's 1 byte, not 1 bit.
1st Nov 2016, 9:28 PM
Anoop Kumar
+ 1
Ou no, the boolean variable does not contain one bit. Because the compiller cant adress or divide single bites in byte for variable. So, the sizes of any variables must be in whole bytes. How many bytes for boolean it depends of different compilators C++. Look in theirs specific dcumentations, or use a sizeof operator. Of course, when yu want to use only one bit for save some boolean value , you have to coding it yourselves, with the bit logic operators upon byte..
2nd Nov 2016, 1:34 AM
Petr Hatina
Petr Hatina - avatar
0
So... Learn C++, Data Types, the operator sizeof(), wrong descriptive image...
1st Nov 2016, 9:44 PM
jiapei100
jiapei100 - avatar