设为首页 加入收藏

TOP

Objective-C学习——布尔类型
2014-11-24 08:32:19 来源: 作者: 【 】 浏览:0
Tags:Objective-C 学习 布尔 类型

参照书中关于布尔类型实例,敲出下面代码



#import


//比较两个整数是否相等



BOOL areIntsDifferent(int num1,int num2){


if (num1==num2) {


return (NO);


}else {


return (YES);


}


//将BOOL值转为相应的NSString类型



NSString *boolString(BOOL noYes){


if (noYes==NO) {


return (@"NO");


}else {


return (@"YES");


}


}



//在main函数中调用上面方法



int main (int argc,constchar * argv[]) {


BOOL areTheyDifferenr;


areTheyDifferenr=areIntsDifferent(5,5);


NSLog(@"are %d and %d different %@",5,5,boolString(areTheyDifferenr));


areTheyDifferenr=areIntsDifferent(23,42);


NSLog(@"are %d and %d different %@",23,42,boolString(areTheyDifferenr));


return0;


}


运行结果:



总结:Objective-C中的BOOL类型与C和JAVA很像,用法也比较简单,需要注意的是Objective-C的BOOL类型是YES值和NO值,而不是true和false。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ 隐式类类型转化 Implicit Cla.. 下一篇Linux中文件名解析处理源码分析

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)
·玩转C语言和数据结构 (2025-12-27 01:19:05)
·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)