Thursday, March 28, 2024 12:12

Table of contents >> Introduction > Boolean variable type

Boolean variable type

The Boolean variable type is probably the easiest type of variable. It doesn’t have a “maximum range”, it can’t produce “overflowexceptions, it’s not affected by precision, etc. In fact, Boolean variable type can only have two values: true  or falseThey are almost exclusively used for calculations of logical expressions. They are declared using the keyword bool.

Here is a short example where we can use Boolean variables:

When compiled and ran, the program will display the following output:
boolean variable type

The concepts explained in this lesson are also shown visually as part of the following video:

EXERCISES
1. Declare a variable isFemale of type bool and assign a value to it depending on your gender.

Solution

Tags: , ,

Leave a Reply



Follow the white rabbit