# Please help to Understand How Increment and Decrement works

rayan alex
Ranch Hand
Posts: 33
1
Hi Please help to understand this out put of this

I counted the output as 35. But correct out put 33. Please help to understand.

This is how i counted.

++x uses incremented value. So first ++x = 11
next ++x increment x again. so second ++x = 12
next x++ uses the current value in the memory. so uses 12. 11 + 12 + 12 = 35

Thank you

Rameshwar Soni
Ranch Hand
Posts: 247
Since you are telling first there is ++x then there is ++x and finally x++, so the way you have written your expression is incorrect.

So instead of this
write your expression neatly i.e.

you will surely get the output as 35.

rayan alex
Ranch Hand
Posts: 33
1
Hi,

Thank you for your reply. But correct out put is 33. I tried to say im getting 35.
I trying to figure out why i'm not getting 33 with my calculation.

Henry Wong
author
Marshal
Posts: 21184
80
• 2
rayan alex wrote:

I counted the output as 35. But correct out put 33. Please help to understand.

This is how i counted.

++x uses incremented value. So first ++x = 11
next ++x increment x again. so second ++x = 12
next x++ uses the current value in the memory. so uses 12. 11 + 12 + 12 = 35

There is no "next ++x" (ie. second pre-increment). There is a space between the two plus signs. It is not a pre-increment, it is two unary plus operators. So, the correct expressions with precedence (and associativity) applied should be...

Henry