shadi
2012-10-17 01:29:31 UTC
1) x = ++y makes y=6 and x=6
2) x = y++ makes y=6 and x=5
3) x = --y makes y=4 and x=4
4) x = y—makes y=4 and x=5
wtf is going on? it makes no sense :-(
i have always known that y++ is shorthand for y=y+1. thus x=y++ becomes x = y+1 = 5 +1 = 6. so x=6 and y=6
also y-- is shorthand for y=y-1. thus x=y++ becomes x = y-1 = 5 -1 = 4. so x=4 and y=4
but that is wrong :-(
i read somewhere that:-
"++x increments the value of x and then returns x
x++ returns the value of x and then increments"
can someone plz explain what is going on and why i am wrong?