Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "->" in Objective C?

I've seen this operator pop up quite a few times in example code in "Learn Objective C on the Mac."

I believe it's an operator in the C language which Objective C inherits. I tried Googling and searching Stack Overflow and oddly nothing came up.

Does it have an English name?

like image 651
Aaronium112 Avatar asked Dec 20 '10 00:12

Aaronium112


People also ask

What does --> mean in C?

operator is used to access a member of a struct, while the arrow operator ( -> ) in C is used to access a member of a struct which is referenced by the pointer in question.

What does the -> operator do?

The -> (arrow) operator is used to access class, structure or union members using a pointer. A postfix expression, followed by an -> (arrow) operator, followed by a possibly qualified identifier or a pseudo-destructor name, designates a member of the object to which the pointer points.

What does arrow mean in Objective-C?

Arrow operator on an Objective-C object (pointer) (at run time) Dereference pointer. Return value of the field.

What does the -> operator mean in C++?

The -> is called the arrow operator. It is formed by using the minus sign followed by a greater than sign. Simply saying: To access members of a structure, use the dot operator. To access members of a structure through a pointer, use the arrow operator. cpp_operators.htm.


1 Answers

It has to do with structures.

When we have a struct available locally on the stack, we access its members with the . operator. For example:

CGPoint p = CGPointMake(42,42);
NSLog(@"%f", p.x);

However, if we instead have a pointer to a structure, we have to use the -> operator:

CGPoint *p = malloc(1*sizeof(CGPoint));
p->x = 42.0f;
NSLog(@"%f", p->x);
free(p);
like image 124
Dave DeLong Avatar answered Sep 23 '22 20:09

Dave DeLong