• Post Reply Bookmark Topic Watch Topic
  • New Topic

Increment/Decrement Operators  RSS feed

 
Ravindranath Chowdary
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

Please look at the following lines of code..

int i = 10;
int k = ++i;

In the above scenario the i value gets incremented to 11 and stores in k. Where as in the follwing lines of code

int i = 10;
int k = i++;
The value of i is first stored in k and later it is incremented. Why it is like this?. If we consider the precedence of operators the post-fix operators has the highest precedence when compared to least priority assignement operators. What is the reason behind it?

Thanks,
Ravindranath
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why it is like this? Because that's how the pre- and post-increment operators are defined. This does not have anything to do with operator precedence.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!