It's not a secret anymore!*
The moose likes Beginning Java and the fly likes working of increment operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "working of increment operator" Watch "working of increment operator" New topic
Author

working of increment operator

D Preethi
Ranch Hand

Joined: May 24, 2008
Posts: 68
Hi All,

I just saw 2 questions on the working of increment operator and, couldn't understand the output for them. Can someone please explain?

Ques 1.


output: 13:0

Ques 2:


output: 14:0

Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Java arithmetic works from left to right. The [] has a high precedence, rather like (), so the i++ in the [] is evaluated first, then the i++ after the = then the 3ed i++.

Remember that i++ increments the value of i, but the whole expression returns the old value of i.

Now you should be able to work it out for yourself.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: working of increment operator
 
Similar Threads
Thread ques.
tricky ques.
Simple variable initialization ques
ques
shift ques.