Friday, September 2, 2011

i=i++ produces the output "0″ instead of "1″.



The code
int i = 0;
i = i++;
System.out.println(i);
produces the output "0″ instead of "1″.



because:


"i = i++" roughly translates to
int oldValue = i;
i = i + 1;
i = oldValue;

No comments:

Post a Comment