Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

x++ , ++x

 
Brian Pianczk
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I find it very helpful to see it in regular ol English.

 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic