• Post Reply Bookmark Topic Watch Topic
  • New Topic

i didnot get the actual output of this simple increment operator.. ++  RSS feed

 
Mr. Sunil Parmar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code:

public static void main(String args[]){
int i = 0;
i = i++ ;
System.out.println(i);
}


Output : is 0

but dont know ?

If any body know the reason behind that than please help...


Thanks & Regards..
 
Smitesh Shinde
Ranch Hand
Posts: 45
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you expect it to print? Please do some research on pre-increment and post-increment operators.
 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That question comes up frequently, and seems to confuse lots of people. Start by looking at this old thread, and this FAQ.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!