What are Boolean Literals in C++?

C++Server Side ProgrammingProgramming

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!
raja
Published on 15-Feb-2018 11:43:22
Advertisements