Differences between BOOL and bool in OC language: ocbool
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
Bool values: false and true, which are the difference between 0 and 1;
BOOL values: FALSE and TRUE, which are the difference between 0 and non-0;
The following is an example.
# Import <Foundation/Foundation. h>
Int main (int argc, const char * argv []) {
@ Autoreleasepool {
BOOL b1 = 3;
Bool b2 = 3;
BOOL b3= 256;
Bool b4 = 256;
NSLog (@ "b1 = % d", b1 );
NSLog (@ "b2 = % d", b2 );
NSLog (@ "b3 = % d", b3 );
NSLog (@ "b4 = % d", b4 );
}
Return 0;
}
The output is as follows:
Because b2 is of the bool type, b2 can only be 1 or 0; that is, b2 = b4 = 1.
Because b3 is of the BOOL type and has 8-bit storage space, the value range of b3 is-256 ~ 255.
Because 256 is converted to hexadecimal = 0X100, b3 = 0; b1 = 3.
Finally, we can conclude that if the variable is of the BOOL type, as long as the value is greater than 255, the result can only be a low 8-bit value;
If b3 = 272, the print result is b3 = 16.