Dremendo Tag Line

Boolean Variable in C++ Programming

C++ Basic Concepts

In this lesson, we will understand what is Boolean Variable and how to declare it in C++ programming, with the help of some examples. We will also play a quiz at the end.

What is Boolean Variable

In C++ program a boolean variable can store value either true or false. To declare a variable of type boolean we use the keyword bool.

video-poster

Syntax of Declaring Character Variable in C++

bool variable_name;

Here bool is used for declaring Boolean data type and variable_name is the name of variable (you can use any name of your choice for example: a, b, c, alpha, etc.) and ; is used for line terminator (end of line).

Now let's see some examples for more understanding.

Example 1

Declare a boolean variable x.

bool x;

Example 2

Declare 3 boolean variables x, y, and z to assign the values true, false and true respectively.

bool x=true, y=false, z=true;

Example 3

Declare a boolean variable x and assign the value false and change it value to true in the next line.

bool x = false;
x = true; //now the new value of x is true

Test Your Knowledge

Attempt the multiple choice quiz to check if the lesson is adequately clear to you.

Test Your Knowledge