Is this pointer assignment correct?
customclass.somearray = &*otherarray;
where somearray and otherarray are NSArray objects.
If not, how do I solve my problem:
I want to share this otherarray object with customclass.somearray. And I want all changes
made to customclass.somearray to be made to the original otherarray too.
Doing it this way, it works. I just want to ask, is it correct?
Your two variables are pointers of the same type, so just assign one to the other:
The way you have written this is unnecessary. Using the dereference operator
*essentially gives you the “contents” of the pointer. The address-of operator&correspondingly gives you the address of whatever you apply it to. Your pointerotherarraycontains an address. If you dereference that address and then take the address of that, you end up right back where you started.Be aware that the left side of this assignment is a property access (assuming that
customclassis also an object and not just astruct). This means that the compiler will change your expression into:That is, it becomes a method call rather than a simple assignment. This does not affect the syntax you should use, however.