C++/Data Type/Bool

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Define and use bool value

#include <iostream>
using namespace std;
int main()
{
  bool outcome;
  outcome = false;
  if(outcome)
    cout << "true";
  else 
    cout << "false";
  return 0;
}


Demonstrate bool values.

 
#include <iostream> 
using namespace std;  
 
int main() { 
  bool b; 
 
  b = false; 
  cout <<  "b is " << b << endl; 
 
  b = true; 
  cout <<  "b is " << b << endl; 
 
  
  if(b)                               // control the if statement 
     cout <<  "This is executed.\n"; 
 
  b = false; 
  if(b) 
     cout <<  "This is not executed.\n"; 
 
  // outcome of a relational operator is a true/false value 
  cout <<  "10 > 9 is " << (10 > 9) << endl; 
 
  return 0; 
}