Priority of C++ operators “&” and “->”
-
03-07-2019 - |
Question
Given the following:
&row->count
Would &(row->count) be evaluated or (&row)->count be evaluated in C++?
EDIT: Here's a great link for C++ precedence.
Solution
OTHER TIPS
As far as precedence rules go, I've always liked the one put forth by Steve Oualline in "Practical C":
There are fifteen precedence rules in C (&& comes before || comes before ?:). The practical programmer reduces these to two:
1) Multiplication and division come before addition and subtraction.
2) Put parentheses around everything else.
May I suggest that you resolve such questions using a test programme? That has the advantage that you will know for sure that the answer is correct for your implementation, and you are not exposed to the risk of badly answered questions.
C operator precendence is explained here
As per the table, -> is higher priority than the & operator, so it's &(row->count)
&(row->count)
-> has a higher priority than & (address of). So your expression would be evalutated as &(row->count)