Arrow operator (->) usage in C

Mohit Deshpande picture Mohit Deshpande · Apr 4, 2010 · Viewed 488.1k times · Source

I am reading a book called "Teach Yourself C in 21 Days" (I have already learned Java and C# so I am moving at a much faster pace). I was reading the chapter on pointers and the -> (arrow) operator came up without explanation. I think that it is used to call members and functions (like the equivalent of the . (dot) operator, but for pointers instead of members). But I am not entirely sure.

Could I please get an explanation and a code sample?

Answer

sepp2k picture sepp2k · Apr 4, 2010

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