Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

i=i++;

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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+"ff"+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+"ff"+j);

i value is:11 j value is:10


could you guys explain this please.
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
A lot of disscussions was there on this topic search for them in the forum.
Any way for the time being just consider the value of i has been assigned before its increment there is no effect in the value of i.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing needless duplicate. And yes, this is one of the most asked questions in this forum, so please search the forum first before posting.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic