BOOL 的默认值

Default value of BOOL(BOOL 的默认值)
本文介绍了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 的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
HTTPS request using volley(使用 volley 的 HTTPS 请求)