For the next code, what it's z? (Java)
int x = 5;
int y = 10;
int z =++x*y--;
The order of priority is: y--, ++x, *, =
.
( https://introcs.cs.princeton.edu/java/11precedence/ )
Why after run the code, z = 60 ?
For the next code, what it's z? (Java)
int x = 5;
int y = 10;
int z =++x*y--;
The order of priority is: y--, ++x, *, =
.
( https://introcs.cs.princeton.edu/java/11precedence/ )
Why after run the code, z = 60 ?
The ++ operator is evaluated before the expression.
i.e.:
int x = 10;
int y = ++x; //y = 11
int z = x ++; // z = 11;
y--
is higher up on the list from your source. However, when the post-decrement happens, it happens after the whole evaluation.
So if you print y
after getting the value of z
, it will be 9.
And the pre-increment happens first, so ++x
becomes 6 within that statement (and obviously multiplies by 10).
See an example in the docs.