| Author |
Incrementing and decrementing.
|
James Elsey
Ranch Hand
Joined: Dec 21, 2007
Posts: 228
|
|
Am I understanding this correctly...?
will print "My int is : 1
The reason for this is because the compiler acts like this : use the variable, then increment it after
will print "My int is : 2
The reason for this is the compiler acts like this : increment the variable BEFORE using it
The compiler therefore must be smart enough to understand the scope of the variable, so it knows when it can increment it?
I'm just trying to understand these operators correctly
Thanks
|
Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
Your understanding is correct. The Java Language Spec includes some detailed and highly technical language about precisely when the increment/decrement can happen in either case, but it boils down to just what you've said here.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Muhammad Khojaye
Ranch Hand
Joined: Apr 12, 2009
Posts: 341
|
|
|
Also see this FAQ.
|
http://muhammadkhojaye.blogspot.com/
|
 |
Vishal Kashyap
Ranch Hand
Joined: Aug 07, 2010
Posts: 73
|
|
100% Correct .......
|
MCSA 2003 | Preparing For OCPJP/SCJP6
|
 |
 |
|
|
subject: Incrementing and decrementing.
|
|
|