I.e., does ObjectiveC behave like C, in that if you create a pointer eg:
NSString* c;
Does c point to nil, or to the random value in the memory area that was reserved for it?
In other words, do pointers get pre-initialized, or do I need to do that myself? As I said, I'm aware this is not the case in C/C++, but I'm wondering if there's some ObjC magic here or not.
Instance variables can be initialized in constructors, where error handling or other logic can be used. To provide the same capability for class variables, the Java programming language includes static initialization blocks.
If you declare a final variable later on you cannot modify or, assign values to it. Moreover, like instance variables, final variables will not be initialized with default values. Therefore, it is mandatory to initialize final variables once you declare them.
An instance variable does not compulsory need to be initialized. Instance variables are accessible inside the same class that declares them.
In Objective-C, any character , numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object (In this case), initialized with that value. C's type suffixes may be used to control the size of numeric literals.
Class instances variables in Objective-C are guaranteed to be initialized to their empty value (0, nil, etc ...)
Class instance variables and static/global variables get initialized to nil/NULL/0/false as appropriate.
However local variables are not initialized.
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