|
|
|
|
|
|
|
The C++ language doesn't have a Boolean data type. In C++, the value 0 represents false, and any nonzero value represents true. Programmers usually use the int type to represent Boolean data: |
|
|
|
|
|
|
|
|
int dataOK;
.
.
.
dataOK = 1; // Store true into dataOK
.
.
.
dataOK = 0; // Store false into dataOK |
|
|
|
|
|
|
|
|
Many C++ programmers prefer to define their own Boolean data type by using a Typedef statement. This statement allows you to introduce a new name for an existing data type. Here is the syntax template: |
|
|
|
|
|
|
|
|
typedef ExistingTypeName NewTypeName ; |
|
|
|
|
|
|
|
|
|
All this statement does is cause the compiler to substitute the word int for every occurrence of the word Boolean in the rest of the program. If a program uses these statements: |
|
|
|
|
|
|
|
|
typedef int Boolean;
.
.
.
float price;
int quantity;
Boolean dataOK; |
|
|
|
|
|
|
|
|
then the compiler substitutes int for Boolean in the declarations: |
|
|
|
|
|
|
|
|
float price;
int quantity;
int dataOK; |
|
|
|
|
|