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 的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!