I'm reading a book called Java and C: Key Differences, Learn Objective-C for Java Developers. (my background is C#/Java so the concept of pointers and managed memory is new to me, so please bear with me)
In chapter 2, it explains pointers with this example:
int i = 1;
int *iptr;
iptr = &i;
*iptr = 2;
I understand the above, where *iptr
is a pointer, it is assigned the memory location of i
, also from the pointer iptr
we can access the value iptr
points to with the *iptr
syntax.
Further down the book there is the following snippet:
//..
NSMutableString *z = [[[NSNutableString alloc]init] autorelease];
[z appendString:@"Zombie "];
//...
From my understanding of chapter 2, the line [z appendString:@"Zombie "]
should have been [*z appendString:@"Zombie "]
instead, as we want the actual NSMutableString
, not to its pointer, to be sent the message appendString
!? I know I'm wrong and there is something that I'm missing, please point me to the right direction.
Many thanks,
Giuseppe