Cpp - Data Type bool Type


bool type can be true or false.

The result of a comparison or a logical association using AND or OR is a boolean value.

The internal value for true will be represented as the numerical value 1 and false by a zero.


#include <iostream> 
using namespace std; 
int main() /*from w ww . ja v  a  2s  .c  o  m*/
     bool ok = true; 
     cout << ok << endl                // 1 
          << boolalpha << ok << endl;  // true 
    return 0; 


Boolean Constants

A boolean expression can have two values that are identified by the keywords true and false.

Both constants are of the bool type.

They can be used, for example, to set flags representing just two states.