• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

x++ , ++x

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure why, what is going on here is not getting through to me.


Produces this output.

When ++y x = 2 and y = 2
When z++ a = 1 and z = 2

why?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
++y is the pre-increment. x = ++y essentially says 'increment y, then use the new value of y to assign to x'

z++ is the post-increment. a = z++ essentially says 'use the current value of z to assign to a, then increment z'
 
Brian Pianczk
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I find it very helpful to see it in regular ol English.

 
Marshal
Posts: 80637
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do a search; that sort of problem causes no end of confusion and there are lots of similar questions here on beginners'.
 
Brian Pianczk
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please do a search; that sort of problem causes no end of confusion and there are lots of similar questions here on beginners'.



I tried, but the search wont take ++ as a valid entry, and I didn't know exactly what else to look for.
 
Campbell Ritchie
Marshal
Posts: 80637
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try searching for "preincrement postincrement" and you get a few hits: 1, 2 (end of discussion), 3, and there are others.
 
reply
    Bookmark Topic Watch Topic
  • New Topic