Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




C++ - BOOLEAN


Boolean represents just two values, i.e. True/1 or False/0.


Boolean Data Type


A bool Data Type can accept only true or false.


Example :



#include <iostream>
using namespace std;

int main() {

	bool x = true;
	bool y = false;
	cout << x << endl;
	cout << y;
    
    return 0;
}


Output :



  1
  0

So, in the above code, we have created a variable named x of Boolean data type and initialised it with value true and internally true gets converted to 1.


bool x = true;
java_Collections


And created one more variable called y of Boolean data type and initialised it with value false and internally false gets converted to 0.


bool y = false;
java_Collections


But if we want to initialise a Boolean type variable with anything other than true/false, it would end up with an error.