How BOOL works?

Can anyone explain how the bool data type works? Please include a sample program (just a simple one) and the explanation on how it works. Thanks!
bool is an 8-bit integral data type that allows only bit 0 to be read. Thus, they can be assigned any value, but when read they will be either 1 or 0.
Last edited on
A bool datatype can accept 2 values (as far as I know), true and false.

You declare and initialize one like this:
bool var=true; //var=1
or
bool var=false; //var=0
More accurately

false = 0
true = not false

ie, anything non-zero is true.

But this is useful only when implicit conversion to bool is performed such as when something like this is done:

1
2
3
int x = 2;
if( x ) 
   cout << "x is non-zero" << endl;


Thanks! I understand it now...
Topic archived. No new replies allowed.