-> 之间的区别和 .在结构中? [英] Difference between -> and . in a struct?
本文介绍了-> 之间的区别和 .在结构中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个结构体
struct account {
int account_number;
};
那和做有什么区别
myAccount.account_number;
和
myAccount->account_number;
还是没有区别?
如果没有区别,为什么不使用 .
表示法而不是 ->
?->
看起来很乱.
If there's no difference, why wouldn't you just use the .
notation rather than ->
? ->
seems so messy.
推荐答案
-> 是 (*x).field
的简写,其中 x
是指向一个struct account
类型的变量,field
是结构体中的一个字段,比如account_number
.
-> is a shorthand for (*x).field
, where x
is a pointer to a variable of type struct account
, and field
is a field in the struct, such as account_number
.
如果你有一个指向结构的指针,那么说
If you have a pointer to a struct, then saying
accountp->account_number;
比
(*accountp).account_number;
这篇关于-> 之间的区别和 .在结构中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文