Forums Register Login

Why include all operators in the precedence hierachy?

+Pie Number of slices to send: Send
Hi,

I am puzzled as to why all operators are listed in the precedence hierachy.

For example it makes perfect sense to have a hierachy for Addition/Multiplication operators so that you can make sense of:

int i = 4 * 9 + 3;

However, why state that the postfix increment operator is of greater precedence that the prefix increment operator? Surely, under any conditions that I can think of they would be goeverned by the associativity rule.

For example :

int i = 1;
int j = i++ + ++i;

The precednce of postfix/prefix are irrelanvent as the operands of the addition operator are evaluated left to right.

There must be a reason, so if any of you good folks could provide me with an example of why precedence rules exist for all operators I would be very grateful.

Thanks in advance,

Simon
+Pie Number of slices to send: Send
Hope this may help.
+Pie Number of slices to send: Send
Hi

Thanks for that. It is an interesting article but it doesn't provide an example of when the precedence of a postfix increment over a prefix increment operator would be relevant.

Thanks

Simon
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 499 times.
Similar Threads
i=i++ .................................?
Q on post increment: JLS explanation
Operator evaluation order
Dissecting the post-fix operator
I am very frustrated after tried dan's mock test...
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:17:28.