wood burning stoves*
The moose likes Beginning Java and the fly likes A question about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question about "Increment"" Watch "A question about "Increment"" New topic
Author

A question about "Increment"

Jack Horner
Greenhorn

Joined: Feb 22, 2005
Posts: 6
hello, everyone!
I think the result is 11. But it is 10. Why???
thanks
Andy Rayner
Ranch Hand

Joined: Dec 09, 2004
Posts: 36
hmm
dont have i=i++
thats like saying i = i = i +1

just have i++ this means i = i+1
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
"i++" is an expression with a side effect. Though its side effect is to increase the value of i by one, its *value* is the value of i before the increment. And that is the value you assign to i (using "=") *after* the increment happened.

With other words: the increment does *not* happen after the whole assignment, but only after the subexpression "i++" got evaluated (to the value of i), and *before* the assignment.

Does that help?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
let us begin with a variable i whose value we have as 5.


Now Consider this...



You guessed it right...

Regards
Prashanth Lingala


Have A Nice Day !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question about "Increment"
 
Similar Threads
about method and variable declaration
doubt related to "++" operator
Mock Question problem
confused
modify method in byte code using ASM.