Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 C 程序中,当我定义一个结构时。
在什么情况下我会使用“->”以及在什么情况下使用“。” ?
例如
typedef struct foo foo; struct foo{ double bar; double bar2; } foo barbar;
我什么时候用barbar.bar,什么时候用barbar->bar?
barbar.bar
barbar->bar
Left of->应该是指针类型,而普通变量/实例为..
->
.
struct foo myFoo
myFoo.
(&myFoo)->
struct foo *myFoo
myFoo->
(*myFoo).
使用 a->作为指向结构的指针,因为它取消引用指针,使用 a.作为结构