C++Introduction to C++Learn C++

Learn How To Use Booleans In C++

multicolored abstract painting

In programming, there are some of the parameters which have two values, as same as 0 and 1 bits in our computers. For these 1 and 0; Yes and No, On and Off, true and false, Enabled or Disabled, etc.. variables there are Boolean operands. We use Booleans, these kinds of switches to check most of the parameters, components, variables in classes, etc. bool data type is used C++ for these variables and it can take the values 1 (true) or 0 (false

Here is an example to use Booleans;

Boolean expressions are used in comparison and it is a C++ expression that returns a boolean value 1 (true) or 0 (false). We can check a boolean variable if it is true or false like this,

We can use comparison operators with if clauses, such as the equal to (==) operator to find out if an expression (or a variable) is true, also that means they are equal.

Here a==b term is a Boolean and return true or false, if clause checks if it is true or false and if it is true that means it is equal to. Same here, we can use greater than or lower than as below,

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

How To Use Basic Methods Of Wide Strings In C++?

C++C++17C++20C++23Learn C++Syntax

How To Use std::make_from_tuple in C++ 17

C++C++17C++20Learn C++

How To Use std::apply With Tuple In C++ 17 And Beyond?

C++C++17C++20Learn C++NumericsSyntax

How To Compute The Greatest Common Divisor And Least Common Multiple in C++?