Boolean data types are named after George Boole who was an English mathematician, so the word “Boolean” should be capitalized. However, the Boolean data type, in C++ uses the keyword bool which is not capitalized. The possible state values for a C++ Boolean are lower case true and false. Be sure to note the difference in capitalization from Python. In Python, these same truth values are capitalized, while in C++, they are lower case.
C++ uses the standard Boolean operators, but they are represented differently than in Python: “and” is given by && , “or” is given by || , and “not” is given by !. Note that the internally stored values representing true and false are actually 1 and 0 respectively. Hence, we see this in output as well.
Boolean data objects are also used as results for comparison operators such as equality (==) and greater than (). In addition, relational operators and logical operators can be combined together to form complex logical questions. Table 2.3.1 shows the relational and logical operators with examples shown in the session that follows.
One or the other operand is true for the result to be true
logical not
Negates the truth value, false becomes true, true becomes false
When a C++ variable is declared, space in memory is set aside to hold this type of value. A C++ variable can optionally be initialized in the declaration by using a combination of a declaration and an assignment statement.
The declaration int theSum = 4; creates a variable called theSum and initializes it to hold the data value of 4git. As in Python, the right-hand side of each assignment statement is evaluated and the resulting data value is “assigned” to the variable named on the left-hand side. Here the type of the variable is integer. Because Python is dynamically typed, if the type of the data changes in the program, so does the type of the variable. However, in C++, the data type cannot change. This is a characteristic of C++’s static typing. A variable can hold ever only one type of data. Pitfall: C++ will often simply try to do the assignment you requested without complaining. Note what happened in the code above in the final output.