之间的区别 - >和。在一个结构? [英] Difference between -> and . in a struct?
本文介绍了之间的区别 - >和。在一个结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个像结构
struct account {
int account_number;
};
那么什么是干什么的区别
Then what's the difference between doing
myAccount.account_number;
和
myAccount->account_number;
或者是不是有区别?
or isn't there a difference?
如果没有区别,你为什么不只是使用
标记,而不是 - 方式>
? - 方式>
显得那么凌乱
If there's no difference, why wouldn't you just use the .
notation rather than ->
? ->
seems so messy.
推荐答案
- >是(* X)点域
,其中 X
是一个指针类型的变量结构帐户
和字段
是场在结构中,如 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屋!
查看全文