Cpp - Data Type bool Type

Introduction

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.

Demo

#include <iostream> 
using namespace std; 
int main() /*from  w  ww  .  j  av  a 2  s .c  om*/
{ 
     bool ok = true; 
     cout << ok << endl                // 1 
          << boolalpha << ok << endl;  // true 
    return 0; 
}

Result

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.