What are Boolean Literals in C++?


Boolean literals are literals that have either the meaning true or false. There are only two Boolean literals in C++: true and false. These literals are of type bool. You can use them as −

Example

#include<iostream>
using namespace std;

int main() {
   bool my_bool = true;
   if(my_bool) {
      cout << "My bool is true!" << endl;
   }
   return 0;
}

Output

This will give the output −

My bool is true!

Updated on: 10-Feb-2020

261 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements