This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

little problem  RSS feed

 
Rippon Jalali
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i am trying to run below program.the output comes='0'.
BUt shouldn't it come '1'.


public class t {
public static void main(String argv[]) {

int i =0;

i=i++;
System.out.println(i);
}


}
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int i = 0;
i=i++; // Here value of the expression i++ equals to 0, i is first incremented to 1, then assigned to the value of the expression, again to 0
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a more detailed explanation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!