Default value of BOOL

suse picture suse · May 27, 2010 · Viewed 50.6k times · Source

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

Answer

kennytm picture kennytm · May 27, 2010

There is no default value if you write

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

It is initialized to garbage.

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

(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).)