Bool has only one byte, two values false and true, 0 is false and non-zero is true.
The following is an example of bool:
# include & ltiostream & gt
Use namespace std
int main()
{
bool b = 2; //After executing this line, b=true (the result is true after the integer 2 is converted into bool type).
If (b)
Cout & lt& lt "OK!" & lt& ltendl
b = b- 1; //After this line is executed, b=false(bool data true will be converted into int value 1 when it participates in arithmetic operation, and the result will be 0 after subtracting 1, and it will be converted into bool value false when it is assigned to b).
If (b)
Cout & lt& lt "Wrong!" & lt& ltendl
Returns 0;
}
Running results:
Extended data:
C99 New Type _ Boolean:
The C99 standard defines a new keyword _Bool, which provides Boolean types. In the past, C programmers always defined Boolean types in their own way. 0 means false, non-0 means true. You can use char type to represent boolean type, or you can use int type to represent boolean type.
Many function libraries have defined their own Boolean types and corresponding macros, enumerations and typedef. C99 brings native Boolean types of C language. The keywords added at the same time in C99 are _ complex number, _ imaginary number, etc.