• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange behaviour of "=" and "++"

 
Omer Haderi
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When I saw this snippet I was totally sure that the output was: 0 1

But it is: 0 0
if we remove line #2 then it will print zeros for ever.

I know that "=" has higher precedence so in line #1 the assignment take place first (so i = 0) and then the post increment (so i becomes 1) but the output is zero

does anyone have any hint ?

cheers,
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this link of this forum:

discussed before


Got it???

Regards,
cmbhatt
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search this forum for "i=i++" and you will find over a thousand topics discussing the same problem. Your answer is to be found there.
 
Omer Haderi
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic