First, you should understand this:
++i
increments i
and returns i
.
i++
returns i
and then increments it.
Now that we have established this, let's break the program down.
At the start of your program, x = 20
. So, ++x
would return 21. Now when you increment x
in this fashion again, you will be incrementing 21 and not 20. So, ++x
+ ++x
will evaluate to 21 + 22
which equals 43. At this point in the program, x
equals 22
. So if you add x++
to 43, you will add the value of x
to 43 and only then increment x
. This ultimately results in y
having a value of 65, and x
having a value of 23.