Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i=i++;

 
Shivaprasad P Kanaganahallimath
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static void main(String [] args){
int i=9;
i=++i;
i=i++;
int j=i;
System.out.println("i value is:"+i+"j value is:"+j);
...
the output is
i value is:10 j value is:10
---------------------------------------------------------------------------

but the following gives different answer
public static void main(String [] args){
int i=9;
i=++i;
int p=i++;
int j=p;
System.out.println("i value is:"+i+"j value is:"+j);

i value is:11 j value is:10


could you guys explain this please.
 
Costa lamona
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

that is because "prefix and postfix" ++, does not differ from each other until the identifier is involved in expression, for instance

produce output 1
but

produce output 0
and

produce output 1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic