object-c的布尔类型关键字BOOL , c的布尔类型关键字bool
区别:object-c中BOOL类型长度1byte, 若将short或int型数赋值给BOOL类型则截取低位1个字节的值,如果最低1位的值为1结果为YES,否则为NO。
c中bool类型实则为int通过宏定义而来,0为false,非0为true.
/***type.m****/
#import <Foudation/Foundation.h>
int main(int argc, char **argv)
{
int i = 256;/*x86体系内存中以十六进制表示的存储情况:
0X00 00 01 00,最右边的一个字节00将被截取参与逻辑运算*/
BOOL yes_no = i;
bool true_false = i;
if (yes_no == YES)
NSLog(@"YES");
else
NSLog(@"NO");
if (true_false)
NSLog(@"true");
else
NSLog(@"false");
return 0;
}
//运行结果:
NO
true