+ 5
by using prefix and postfix the answer comes same eg; int x=42; x++;. //output=43 int x=42; ++x;. //output=43
3 odpowiedzi
+ 12
difference is if we say x=0
and use this code
y=x++;
the answer is x=1 but y=0
_____
but if we use code like this
y=++x;
the answer is x=1 y=1
in other word y=x++
y=x
x=x+1
and y=++x
x=x+1
y=x
+ 3
Since you are using only 1 operation per statement thew is no question of precedence.
However if you use a statement which has more than 1 operator per statement like
x=y++; or x=++y; then there is a difference
+ 1
The answer can be explained a bit more simply : when you write
"int x=42;
y= x++;"
that means that you first assign x to y (y=x) and then add +1 to x variable. In that case the y variable output will be the same as it was before adding the ++. And if you use
"int x=42;
y=++x;"
then that means that you first add +1 to x variable and then assign it to y variable, so the output with ++x is 43