Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Operators & Assignments

 
N Rao
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
please help, might be a basic doubt but I really find it tricky.

Given the following:

In the above snippet, please note that Set-1 changed the value of i (from 10 to 11). But Set-2 didnot (i stays at 11), while Set-3 did (from 11 to 12) and never again did the value of i change.

Can you please explain the above phenomenon? May be I am ignoring some basic rule or may be it is an anomaly? Kindly explain!

Thanks in advance,
cheers,
Nanjunda
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i = i++; doesn't actually change the value of i at all. It's a dummy operator.
What happens is
 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rao,

In this code snippet, you must first see what is the result of the expression at the right side of the equal sign, then assign it to i.
 
N Rao
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was great!

Thanks a lot, Jeroen and Serge for your explanations that helped me understand this more clearly.

cheers,
N Rao
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also read about this in my blog, here.
 
N Rao
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Corey,
That was an interesting site indeed!

I already learnt few new things out there.

Thanks a lot for that!

Cheers,
~NRao
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic