If you create a local static variable inside a method, is that initialised once per instance, or once per program?
Does this differ between C++ and Objective-C?
If you create a local static variable inside a method, is that initialised once per instance, or once per program?
Once per program.
Even if it is in a non-static class member function, it is not associated with any class instance; there will only be one instance of the variable in the whole program, initialised just once.
Does this differ between C++ and Objective-C?
In C++, it is initialised the first time the function is called. In C (and Objective-C), it is initialised prior to program startup. In practice, this doesn't make a difference, since the initialisation can't have any side effects in C.
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