• 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:
  • 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

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.

 
Get me the mayor's office! I need to tell her about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic