Boolean Values & Expressions in C++ | Topic 6 | VU Insider

During program writing, sometimes you need a data type that only can have one of two values like True or False, Yes or No, etc. For this this purpose, C++ provides bool data type which can take values 1(true) and 0(false).
  • Boolean Values
  • Boolean Expressions

Boolean Values

A boolean variable with only true and false values declared with bool function.

Example for Boolean Values:
bool isCodingFun = true;
bool isLightGone = false;
cout << isCodingFun; // Returns true (1) as output
cout << isLightGone; // Returns false (0) as

Boolean Expressions

An expression that returns a boolean value: 0 (false) or 1 (true) is said to be Boolean Expression.

Example for Boolean Expressions:
int x = 3;
int y = 4;
cout << (x>y); // returns 0 (false) as 3 is not > 4code-box

Post a Comment

Previous Post Next Post