course of action is to be taken. A conditional expression evaluates to either a true or
false value. In C, a true value is any nonzero value, including negative numbers. A
false value is 0. This approach to true and false allows a wide range of routines to be
coded extremely efficiently.
C++ fully supports the zero/nonzero definition of true and false just described. But
C++ also defines a Boolean data type called bool, which can have only the values true
and false. As explained in Chapter 2, in C++, a 0 value is automatically converted into
false and a nonzero value is automatically converted into true. The reverse also
applies: true converts to 1 and false converts to 0. In C++, the expression that controls a
conditional statement is technically of type bool. But since any nonzero value converts to true and any zero value converts to false, there is no practical difference between C
and C++ on this point.
false value. In C, a true value is any nonzero value, including negative numbers. A
false value is 0. This approach to true and false allows a wide range of routines to be
coded extremely efficiently.
C++ fully supports the zero/nonzero definition of true and false just described. But
C++ also defines a Boolean data type called bool, which can have only the values true
and false. As explained in Chapter 2, in C++, a 0 value is automatically converted into
false and a nonzero value is automatically converted into true. The reverse also
applies: true converts to 1 and false converts to 0. In C++, the expression that controls a
conditional statement is technically of type bool. But since any nonzero value converts to true and any zero value converts to false, there is no practical difference between C
and C++ on this point.
No comments:
Post a Comment