The value of BOOL in objective C is always NO(by default). But recently I encountered a case where the value of BOOL variable was returning YES (by default). Can anybody explain this to me ?
If you declare a variable without initialization, the OS will allocate memory randomly and at that instant allocated memory may contain some garbage value. That garbage can represent No also or may be Yes value.
Recommended: Always declare a variable with proper initialization to avoid bugs in your code.
BOOL
has no value as it is a type.
You probably mean variables of type BOOL. There are different types of variables, which have different initialization semantics:
alloc
promises to set all instance variables to zero, which in case of BOOL means NO
;If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With