I. Differences between bool and bool
1. Different Types
Bool is int type
Bool is Boolean
2. Different Lengths
Bool has only one byte
The bool length depends on the actual environment. Generally, it can be regarded as 4 bytes.
3. Different values
The bool values are false and true, which are the difference between 0 and 1. False can represent 0, but there are many types of true, not only 1.
If multiple bool objects are listed together, each bit may be occupied, depending on the compiler.
Bool is the typedef int bool defined by Microsoft (in windef. h ).Unlike bool, It is a three-value logic,True/false/error. If the returned value is an integer greater than 0, true is returned. If the returned value is 0, false is returned. If the returned value is-1, error is returned.
In Win32 API, many functions with return values of bool are three-value logic. For example, getmessage ().
Bool getmessage (
Lpmsg, // message information
Hwnd, // handle to window
Uint wmsgfiltermin, // first message
Uint wmsgfiltermax // last message );
If the function retrieves a message other than wm_quit, the return value is nonzero.
If the function retrieves the wm_quit message, the return value is zero.
If there is an error, the return value is-1.
**************************************** **************************************** **************************************** *********************
Edit this section II. boolean variable bool
Bool is a Boolean variable, that is, the identifier of a logical variable, similar to float or double, but float defines the floating point type and double defines the Double Precision Floating Point type.
A similar type bool is provided in objective-C, which has yes and no values.
The values of Boolean variables are true and false ).
Boolean variables can be used in logical expressions, that is, logical operations such as "or" and "Non" and relational operations such as greater than or less. The logical expressions are true or false.
Bool can be used to define the function type as boolean. A function can contain statements such as return true and return false.
Boolean computation results are often used in conditional statements,
If (logical expression)
{
If it is true, execute here;
}
Else
{
If it is false, execute here;
};
Iii. Small bool examples
(1)
# Include <iostream>
Using namespace STD;
Int main ()
{
Bool B = 1; // after this row is executed, B = 1 (true)
If (B)
Cout <"OK! "<Endl;
B = B-1; // after this line is executed, B = 0 (flase)
If (B)
Cout <"error! "<Endl;
Return 0;
}
Running result: OK!
(2)
# Include <iostream>
Using namespace STD;
Int main ()
{
Bool B = 1; // after this row is executed, B = 1 (true)
If (B)
Cout <"OK! "<Endl;
B = B + 1; // after this row is executed, B = 1 (true)
If (B)
Cout <"error! "<Endl;
Return 0;
}
Running result: OK!
Error!
If you want to know more, you can change B to bool B = 0 when defining B. Check the running result.
From Baidu Encyclopedia: http://baike.baidu.com/view/1557195.html? WTP = TT