C 中的箭头运算符 (->) 用法

问题描述:

我正在阅读一本名为21 天自学 C"的书(我已经学习了 Java 和 C#,所以我的学习速度要快得多).我正在阅读有关指针的章节,->(箭头)operator 没有解释就出现了.我认为它用于调用成员和函数(类似于 . (点)运算符,但用于指针而不是成员).但我并不完全确定.

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?

foo->bar 等价于 (*foo).bar,即它得到来自 foo 指向的结构的名为 bar 的成员.

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