Hi, I have a doubt about this arguments.
In a book is written about postfix ++ operator:
"Placing it after the operand means that the operand is affected after all other computation of the expression is completed"
and in example:
Code:
int var1, var2 = 5, var3 = 6;
var1 = var2++ * --var3;
and then write:
"Before the expression is avaluated, the -- operator preceding var3 takes effect, changing its value from 6 to 5. You can ignore the ++ operator that follows var2, as it won't take effect until after the calculation is completed"
and in the operator precedence chart (prefix++) have more precedence of (postfix++).
Well, all right but....that logic don't function with this code:
Code:
int a = 5;
int b = a++ * a--;
Follow that logic in b the value after calculus would be 25 but.....no is 30.
Why? In this case (postfix++) don't aspect to solve entire expression but...after a++ they change the value of a and take new value in a-- and THEN calculate product.
Can you explain me all this better? Thanks :)