BOOL 的默认值 [英] Default value of BOOL

查看:22
本文介绍了BOOL 的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Objective-C 中 BOOL 变量的默认值是多少?

What is the default value of a BOOL variable in Objective-C?

推荐答案

没有写默认值

-(void)somemethod {
  BOOL x;  // <--- no default value

它被初始化为垃圾.

但是,对于 BOOL ivar,它将被初始化为 NO,因为在初始化时整个实例都被填充为 0.

However, for a BOOL ivar, it will be initialized to NO, as the whole instance is filled with 0 on initialization.

(注意:启用ARC后,本地对象指针将始终有一个默认值nil,但是像BOOL这样的非对象类型的局部变量仍然会被初始化垃圾.请参阅 局部变量设置为零?(Objective-C).)

(Note: When ARC is enabled, local object pointers will always be have a default value nil, but local variables of non-object types like BOOL are still initialized to garbage. See Local variables set to nil? (Objective-C).)

这篇关于BOOL 的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆