This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 37941
    
  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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: working of increment operator
 
Similar Threads
Thread ques.
tricky ques.
Simple variable initialization ques
ques
shift ques.