C 中的箭头运算符 (->) 用法 [英] Arrow operator (->) usage in 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.
这篇关于C 中的箭头运算符 (->) 用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!