Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

++

 
Miran Cvenkel
Ranch Hand
Posts: 202
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
out of curiosity:



I get out 0, but then again i have no idea how that work at all.
Next:

gives me 1.

I would expect 1 in first case.

as it looks now:

would give same thing at start, but the code is different.



Any thought about that ?
 
Stuart James
Greenhorn
Posts: 4
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I am understanding your question correctly, the first call to out.Print gives 0 because you have used the postfix increment operator - the value of c is printed, then incremented.

If you want to see 1 in the first call you need to use the prefix increment operator (++c). Then the value is incremented prior to printing.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 for the subject.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To summarize it with code:

 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question arises frequently. We have an FAQ about it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic