* 和 & 是什么意思?如果参数很复杂,运算符会进行运算吗?
简单地说,
&someObject->someAttribute.someMember;
相当于
&(someObject->someAttribute.someMember);
or
(&someObject)->someAttribute.someMember;
or
(&(someObject->someAttribute)).someMember;
或者 为了安全起见,您真的应该在其中添加显式括号吗?
Simply, is
&someObject->someAttribute.someMember;
equivalent to
&(someObject->someAttribute.someMember);
or
(&someObject)->someAttribute.someMember;
or
(&(someObject->someAttribute)).someMember;
Or should you really put explicit parenthesis there just to be safe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它相当于:
->
和.
具有相同的优先级并且是左关联的。一元-&
的优先级较低。如果您有非常复杂的表达式,那么您当然应该使用括号来对事物进行分组并阐明您的代码。不过,这并不是特别复杂。在 C 和 C++ 中类似这样的代码很常见。
It is equivalent to:
The
->
and.
have equal precedence and are left-associative. The unary-&
has lower precedence.If you have very complex expressions, then you should certainly use parentheses to group things and clarify your code. This isn't particularly complex, though; it is quite common to see code like this in C and C++.
请参阅Wikipedia
向下滚动到运算符部分。图表中较高框中的运算符在较低框中的运算符之前被考虑。另请参阅关联性规则。
这在某种程度上是一个偏好问题,但作为一般规则,如果您在解决问题时遇到困难,那么其他人也会遇到困难。有疑问时请加上括号。
See Wikipedia
Scroll down to the operators section. Operators in a higher box in the chart are considered before operators in a lower box. Also see the rules for associativity.
This is somewhat of a preference issue but as a general rule, if you're having any trouble figuring it out, then someone else will too. Put parenthesis when in doubt.
如果您想要 someMember 的地址,则 &(someObject->someAttribute.someMember) 或 &someObject->someAttribute.someMember。
第一个是 someObject->someAttribute,第二个是它的成员 somMember,第三个是 &
地址
结构xxx{
整数xx;
};
结构温度{
整数x;
结构xxx ptr;
};
If u want address of the someMember then &(someObject->someAttribute.someMember) OR &someObject->someAttribute.someMember.
First someObject->someAttribute and second to its member somMember and third is &
address
struct xxx{
int xx;
};
struct temp{
int x;
struct xxx ptr;
};