Win a copy of Mesos in Action this week in the Cloud/Virtualizaton 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: 48972
60
  • 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