Objective-c pointer assignment and reassignment dilema

Posted by moshe on Stack Overflow See other posts from Stack Overflow or by moshe
Published on 2011-01-14T07:40:20Z Indexed on 2011/01/14 7:53 UTC
Read the original article Hit count: 205

Filed under:
|

Hi,

If I do this:

1 NSMutableArray *near = [[NSMutableArray alloc] init];
2 NSMutableArray *all = [[NSMutableArray alloc] init];
3 NSMutableArray *current = near;
4 current = all;

What happens to near?

At line 3, am I setting current to point to the same address as near so that I now have two variables pointing to the same place in memory, or am I setting current to point to the location of near in memory such that I now have this structure:

current -> near -> NSMutableArray

The obvious difference would be the value of near at line 4. If the former is happening, near is untouched and still points to its initial place in memory. If the latter is happening,

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about pointers