x++ uses post increment and it means it increments its value AFTER the statement which x is in. So x still equals -1. Later in the same statement will get to a ++x, which increments x on the spot, so now x=0. So now y = 0. But don't forget that x now = 1 because we had a post increment operation in the statement, so x got incremented after the statement.

I think that was the trickiest part, the rest should be ok to understand.

First We need to know one thing..Individual Static BLock with Variable X is not accessible for Main().. so X=0 and y=0 in main()

before coming to this following exp x = -1 and y = 0 y = x++ + ++x; in this exp first x++ will be executed -> x++ -> x= -1 + 1 -> x= 0 in this exp next ++x will be executed -> ++x -> x = 0 + 1 -> x = 0 next we will go for total exp

but what i have make the final conclusion is x+++++x is equalant to (x++)+(++x); and not =((x++)++)+x and we can't write x+++++x as we have to put space like x++ + ++x as its giving error in the link above ?

any way do post ur comments regards [ June 11, 2005: Message edited by: amit taneja ]

your doubt helped me in understanding the increment operator. In case of a post increment operator, its value gets incremented after the expression is evaluated.

For e.g in the expression, x=-1; y=0; y = x++ + ++x;

x++ itself is an expression, but usually we make mistake in taking the whole equation for y as an expression while applying the post increment rules.

if we take x++ or ++x itself as an expression, the execution steps are as follows,

y = (-1) + ++x; /* the value of x is substituted as it is in the expression x++ and then the value is incremneted by 1, so x now becomes 0*/

y= (-1) + (1) /*since the pre increment operator increments the value of x during execution of the expression x gets incremneted from 0 to 1.