Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt with post-increment operator  RSS feed

 
Ranganathan Chandrasekaran
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this piece of code:

int i=0;
i=i++;
System.out.println(i);

Could you please explain why it prints a zero instead of one?

Thanks in Advance,
Ranganathan
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ranganathan",

Your screen name does not meet our Naming Policy requirements. Basically, we require a real sounding first AND last name, separated by a space. Please go here and update your profile.

thanks
 
Sam Wang
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are maybe different results in different implements of c. but in the platform of java, i=0 is the only answer.
Anyway, if you find code like this in your project, the author must be a bad guy. He may try to play a trick or want to bury this project!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!