让我们有两行代码:
&car->speed
&(car->speed)
- 这两行是否等价?在这两种情况下我都能得到
speed
的地址吗? - 如果它们是等价的,那么选择什么作为编码约定更好?
最佳答案
Are these two lines equivalent? Will I get in both cases address to the speed?
是的。 ->
比一元 &
具有更高的优先级,因此 &car->speed
和 &(car->speed)
是等价的。
If they are equivalents, what is better to choose as coding convention?
选择第二个,因为它显示了您对 speed
地址感兴趣的预期行为。
关于c++ - 使用带或不带括号的 C 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25919241/