posted 23 years ago
int i = ++k + k++ + +k ;
Ok. lets expand this expression to its literal meaning. Operands in an expression are evaluated first irrespective of precedence.
int i = (++(k=k)) + (k=k)++ + +(k=k);
Now the value of k is inserted from left to right.
So
(++(k=k)) is evaluated first which returns 2 and then that value is used in the expression.
Next term, (k=k)++, first k=2 is used in the expression and then k incremented. So k=3 and the current total value of the expression is 4.
Last, +k is evaluated which is obivously just +3.
So, the result is 7.
venkat, post/pre fix precedence rules cannot be applied here because, there is only + operation here through out the expression.