File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Incrementing and decrementing.

 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see this FAQ.
 
Vishal Kashyap
Ranch Hand
Posts: 73
BSD C++ Fedora
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
100% Correct .......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic