What does the Asterisk * mean in Objective-C? What does the Asterisk * mean in Objective-C? objective-c objective-c

What does the Asterisk * mean in Objective-C?


an * is actually an operator to de-reference a pointer. The only time it means "hey i'm a pointer" is during variable declaration.

Foo* foo  // declare foo, a pointer to a Foo object&foo      // the memory address of foo*foo      // de-reference the pointer - gives the Foo object (value)


mmattax well covered the distinction between declaration (as a pointer) and dereferencing.

However, as to your point about:

  (*myVar).myStructComponentX = 5;

to access a member of an instance of a C struct (as this is) you can do what you did , or more commonly you use the -> notation:

  myVar->myStructComponentX = 5;

Objective-C is a little confusing here because it recently (in ObjC 2.0) introduced property syntax, which is a short cut for:

  int val = [myObject someIntProperty];

and can now be written as:

  int val = myObject.someIntProperty;

This is Objective C (2.0) syntax for accessing a property which you have declared (not an actual member variable), whereas your example was accessing a member of a C struct.

Make sure you are clear on the difference.


As I said in my answer of your previous question, @"yep" is already a pointer, so there is no need of * before myString which is also a pointer. In this case, you assign pointers not values.