This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

working of increment operator

 
D Preethi
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic