I stumbled across the following code when coding. I'm wondering how it even compiles without warning?
NSString *str = 0
Logging it returns (null) so it's not setting the string literally. Why does this work?
I stumbled across the following code when coding. I'm wondering how it even compiles without warning?
NSString *str = 0
Logging it returns (null) so it's not setting the string literally. Why does this work?
With this line, you're assigning the zero value to a pointer, which is only a convention to define a null pointer, which doesn't address to any memory.
Here (Why is address zero used for the null pointer?) you have a discussion about why zero is the null pointer convention in c.
In C and, by extension, Objective-C, 0 is the equivalent of NULL and nil and Nil. It's an integer but it freely assigns to any pointer type.