When do we use bool variable ? | Sololearn: Learn to code for FREE!

+1

When do we use bool variable ?

9/19/2017 8:50:05 PM

Ahmad Alzohaile

7 Answers

New Answer

+8

When a true/false value is required to be stored/tracked http://www.learncpp.com/cpp-tutorial/26-boolean-values/

+5

Any time you have a yes or no question/answer.

+5

I used one here to verify my number. https://code.sololearn.com/cF7iOkU73BYy/?ref=app

+2

Think of it as a fork in the road of your code. If true, do one thing, if false do something else. Boolean variables should be named appropriately too - by convention you should prefix your variable names with "Is". For example, if determining that the side of a coin is heads I might create the variable name "IsHeads" .

+1

In any flow control statements (if/else, switch, loops...)

+1

0

for true or false