在括号需要从一个指针得到一个结构成员的地址结构体如在QUOT;及(S-GT&; VAR)QUOT; VS"&安培; S-> VAR"? [英] Are parenthesis needed to get the address of a struct member from a pointer to the struct as in "&(s->var)" vs "&s->var"?

查看:113
本文介绍了在括号需要从一个指针得到一个结构成员的地址结构体如在QUOT;及(S-GT&; VAR)QUOT; VS"&安培; S-> VAR"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构STR * S ;

VAR A变量s 。为&放大器; S-> VAR 等于及(S-> VAR)?

推荐答案

行为的角度来看,是的,他们是因为等价的成员访问 - > 经营者具有更高的precedence比地址的&安培; 运营商

Behavior-wise, yes they are equivalent since the member access -> operator has a higher precedence than the address-of & operator.

可读性明智的,第二个及(S-> VAR)&放大器更可读; S-> VAR 并应pferred在第一种形式$ p $。对于第二种形式,及(S-> VAR),你就不必去猜测它实际上是在做什么,你知道前pression括号总是首先评估。如有疑问,请使用括号。

Readibility-wise, the second one &(s->var) is much more readable than &s->var and should be preferred over the first form. With the second form, &(s->var), you won't have to second-guess what it's actually doing as you know the expression in the parentheses are always evaluated first. When in doubt, use parentheses.

这篇关于在括号需要从一个指针得到一个结构成员的地址结构体如在QUOT;及(S-GT&; VAR)QUOT; VS"&安培; S-> VAR"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆