i gets incremanted after the assignment, so x==0; if you did
i would be incremanted before the assignment, so x==1. You wouldn't normally do i=i++ - perhap's you're thinking of i++ or i+=1 or i=i+1, which all simply increment i by 1.
As an aside, I feel strongly that pre-increment (++i) works in a much more intutive way than post-increment (i++), and blame lots of textbook and programming standards writers (starting with Kernighan and Richie) for using post-increment so much where it is not needed. Personally, I always use pre-increment unless I have a real need for the special behaviour of post-increment, and I try and teach my development teams the same habit.
when u say int i; i = i++; System.out.println(i) The output is 0 because in int i ; i is set to 0 then when u say i = i + + this means increment the value of i after performing the task assigned in this case the task is System.out.println(i) hence o if u put it in a loop the next time i = i ++ is executed it will print 1
sona<br />SCJP
Grant Crofton
Ranch Hand
Joined: Nov 08, 2000
Posts: 154
posted
0
Yeah, I was always taught post-increment, and now I always use it unless I have a reason not to. I suppose pre-increment is more intuative, but you tend to get into a 'style', don't you. I think maybe people teach i++ because it's more like i=i+1. Or maybe it just rolls of the tongue easier.
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6919
posted
0
Depends how you say it. I find "increment i" to be more sensible to say that "i increment" (which usually begs the question "you increment what?")