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.

Was it helpful?

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.

This is already asked. But here is a link.

Edit: Ok this question is very similar. And possibly there is an other one.

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top