Does all method of a class returns address?

Does methods of a class return address of its instances?
Look at this code.


NSHost*instance=[NSHost currentHost];
NSString*answer=[instance localizedName];
NSLog(@"@",answer);
  1. Does currentHost method of NSHost class return address of the instances or all method of class return address of its instances?<for the first line of code
    2)Can you store a pointer in a variable? Since localizedName returns a pointer, then storing pointer in a variable is like storing a variable in a variable because pointer is also a variable when we first set it. < for 2nd line of code
    the book says localizedName returns a pointer to an instance of NSString

[quote]1) Does currentHost method of NSHost class return address of the instances or all method of class return address of its instances?<for the first line of code
[/quote]
Class methods can return anything, not just instances.

That depends on the type of the variable. It has to be a compatible pointer variable or a variable of type void *.

NSString * str = [NSMutable stringWithFormat:@"%s", "Hello"];

void * foo = str;

wait does it mean in the code i posted up there, we’re storing a pointer in a variable?

[quote=“chanyeechoong”]wait does it mean in the code i posted up there, we’re storing a pointer in a variable?

NSHostinstance=[NSHost currentHost];
NSString
answer=[instance localizedName];
NSLog(@"@",answer);

[/quote]
Yes, you have an instance variable and an answer variable that just so happen to be pointers, which mean its pointing to a memory address and also containing data you initialized from the method(s): currentHost and localizedName…