The Boolean data type is also known as the logical data type and represents the concepts of true and false. The name "Boolean" comes from the mathematician George Boole; who in 1854 published: An Investigation of the Laws of Thought. Boolean algebra is the area of mathematics that deals with the logical representation of true and false using the numbers 0 and 1. The importance of the Boolean data type within programming is that it is used to control programming structures (if then else, while loops, etc.) that allow us to implement "choice" into our algorithms.
The Boolean data type has the same attributes and acts or behaves similarly in all programming languages. The rules within the C++ programming language are:
|C++ Reserved Word||bool|
|Represent||Logical concepts of true and false|
|Size||Usually 1 byte|
|Domain (values allowed)||0 meaning false, and 1 meaning true|
|C++ syntax rule||true and false are reserved words that can be used as values in expressions|
|C++ concept/rule||Any value from any data type can be demoted into a Boolean data type with zero representing false and all non-zero values representing true|
Most control structures use a test expression that executes either selection (as in the: if then else) or iteration (as in the while; do while; or for loops) based on the truthfulness or falseness of the expression. Thus, we often talk about the Boolean expression that is controlling the structure. Within many programming languages, this expression must be a Boolean expression and is governed by a tight set of rules. However, in C++ every data type can be used as a Boolean expression because the value of any data type within C++ can be demoted into a Boolean value.
Within most languages, expressions that yield Boolean data type values are divided into two groups. One group uses the relational operators within their expressions and the other group uses logical operators within their expressions.
Within the C++ programming language the Boolean data type is one of the standard or basic data types and is a member of the integer family.
- A data type representing the concepts of true and false.
- Test Expression
- An expression used to control programming structures.