Arrow operator (->) usage in C Arrow operator (->) usage in C c c

Arrow operator (->) usage in C


foo->bar is equivalent to (*foo).bar, i.e. it gets the member called bar from the struct that foo points to.


Yes, that's it.

It's just the dot version when you want to access elements of a struct/class that is a pointer instead of a reference.

struct foo{  int x;  float y;};struct foo var;struct foo* pvar;pvar = malloc(sizeof(struct foo));var.x = 5;(&var)->y = 14.3;pvar->y = 22.4;(*pvar).x = 6;

That's it!


a->b is just short for (*a).b in every way (same for functions: a->b() is short for (*a).b()).