I'm reading precedence and associativity. In the table, I observed these two things -
(i) precedence of postfix increment(or decrement) operator is greater than precedence of prefix increment(or dec.) operator.
(ii) associativity of postfix inc.(or dec.) operator is left-to-right but that of prefix increment(or dec.) operator is right-to-left.
I'm not sure why it is needed. Can anyone help me by showing code(separately for each case), which shows the need of these two facts? Thanks.
I tried to think about cases but not getting any such(as I'm very new to programming).
This is needed for an expression like
data = *pointer++;
You to obtain the value at pointer in data, and then increment it to the next element. If the precedence of the postfix weren't greater, you'd end up with an incremented value in data.
And the associativity of the prefix operator is right-to-left because you want an expression like
data = **pointer_to_pointer;
to be evaluated from right to left as if you'd write
data = *(*pointer_to_pointer);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With