Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • just want to know if i am correct or not that bool is single bit can only hold 0 or 1 Commented Jul 20, 2021 at 21:25
  • @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. Commented Jul 20, 2021 at 21:58
  • 1
    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. Commented Jul 21, 2021 at 6:48
  • 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. Commented Jul 21, 2021 at 14:35