Timeline for Can bool variable be NULL
Current License: CC BY-SA 4.0
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 21, 2021 at 14:35 | comment | added | JRobert | A boolean test doesn't look only at bit 0 in most implementations; rather, it may look at the entire variable and test it's "zero-ness. Zero == false; non-zero == true. That still doesn't leave any values for a third distinct meaning (such as NULL). If you need that, an enum would be a better choice. | |
| Jul 21, 2021 at 6:48 | comment | added | the busybee |
Depending on the compiler's implementation, a bool can also be as wide as an int. There is no guarantee that it takes just 8 bits (chapter 8.3.3 in the C++17 standard). However, some systems support bit accesses (8051 microcontroller, for example), and some compilers for these support 1-bit bools.
|
|
| Jul 20, 2021 at 21:58 | comment | added | lights0123 |
@Shahreza yes, you can only store a 0 or 1 in a bool, i.e. a single bit. However, because you can't address single bits, each bool takes up a full byte, even though you can't use the other 7 buts.
|
|
| Jul 20, 2021 at 21:25 | comment | added | Shahreza | just want to know if i am correct or not that bool is single bit can only hold 0 or 1 | |
| Jul 20, 2021 at 21:03 | history | answered | lights0123 | CC BY-SA 4.0 |