wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Operators & Assignments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Operators & Assignments " Watch "Operators & Assignments " New topic

Operators & Assignments

N Rao

Joined: May 17, 2004
Posts: 14
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,
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
i = i++; doesn't actually change the value of i at all. It's a dummy operator.
What happens is

Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
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

Joined: May 17, 2004
Posts: 14
That was great!

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

N Rao
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
You can also read about this in my blog, here.

SCJP Tipline, etc.
N Rao

Joined: May 17, 2004
Posts: 14
Hi Corey,
That was an interesting site indeed!

I already learnt few new things out there.

Thanks a lot for that!

I agree. Here's the link: http://aspose.com/file-tools
subject: Operators & Assignments
It's not a secret anymore!