• Post Reply 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Q abt increment operator

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int j = 0;
int x = 0;

j++;
x = x++;


System.out.println("The value of j = " + j);
System.out.println("The value of x = " + x);


output :

is The value of j = 1
is The value of x = 0


can anyone please explain the difference in the output ?
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Haricharan Ramachandra:
int j = 0;
int x = 0;

j++;
x = x++;


System.out.println("The value of j = " + j);
System.out.println("The value of x = " + x);


output :

is The value of j = 1
is The value of x = 0


can anyone please explain the difference in the output ?



There are a lot of posts going on about this very topic at present. Try reviewing:

increment/decrement
increment operatorsPostfix operator evaluation

Finally, review the following articles:
Article #1
Article #2
 
Haricharan Ramachandra
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for those links Chris, they are great.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic