The Boolean type in Object-c is 10 years older than the bool type in C, and has a yes and no two values. The Boolean type bool in Object-c is actually a signed character type (signed char), which uses a space of 1byte, or 8bit, where Yes is defined as 1,no defined as 0. Assigning an integer greater than 1 bytes (such as short or int) to a bool variable is truncated and retains only the 8 bits at the end.
The following are examples of the types of bool used in OBJECT-C:
#import<Foundation/Foundation.h>//compare whether two int numbers are the sameBOOL Areintsdifferent (intThing1,intthing2) { if(thing1==thing2)returnNO; Else returnYES;}//returns the NSString string corresponding to the number of type boolNSString *boolstring (BOOL yesNo) {if(yesno==YES)return @"YES"; Else return @"NO"; }intMainintargcConst Char*argv[]) {BOOL aretheydifferent; Aretheydifferent= Areintsdifferent (6,6); //The following%@ represents the NSString placeholderNSLog (@"is %d and%d different?%@",6,6, Boolstring (aretheydifferent)); Aretheydifferent= Areintsdifferent ( at, the); NSLog (@"is %d and%d different?%@", at, the, Boolstring (aretheydifferent)); return 0;}
Results of the output:
2016-04-04 23:18:48.964 hello-obj[1267:84194] is 6 and 6 different? no2016-04-04 23:18:48.965 hello-obj[1267:84194] is and different? YES
Type of bool in Object-c