首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

BOOL跟bool

2013-03-26 
BOOL和boolBOOL 和 bool 不是同一个对象,不能混为一谈。上一个例子吧:bool b1 true BOOL b2 truebool

BOOL和bool

BOOL 和 bool 不是同一个对象,不能混为一谈。

上一个例子吧:

  bool b1 = true;

 BOOL b2 = true;

  bool b3 = 11;

 BOOL b4 = 11;

if(b1) NSLog(@"b1 is true");

if(b2) NSLog(@"b2 is true");

if(b3) NSLog(@"b3 is true");

if(b4) NSLog(@"b4 is true");

输出结果:

b1 is true;

b2 is true;

b3 is true;

    b4没有输出。

  1. BOOL a = YES;  
  2. BOOL b = NO;  
  3. if(a == YES){  
  4.      NSLog(@"a==YES");  
  5. }  
  6. if(b == NO){  
  7.      NSLog(@"b==NO");  
  8. }  
  9. if(a){  
  10.      NSLog(@"a is true");  
  11. }  
  12. if(b){  
  13.      NSLog(@"b");  
  14. }  

输出结果:

  1. a==YES  
  2. b==NO  
  3. a is true 














热点排行