Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Incrementing and decrementing.  RSS feed

 
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • 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
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • 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.
 
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also see this FAQ.
 
Ranch Hand
Posts: 73
BSD C++ Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
100% Correct .......
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!