• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Operators Doubt

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below is a Two Minute Drill from chapter 4, Operator (K & B Book)
Page 300

> Increment/Decrement Operators

In any expression, both operands are fully evaluated before the operator
is applied.



Can anyone explain the above statement with an example.
Any suggestions are welcome.

Regards,
Hardik.S.Raja
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok ,explanation for this is here,shown below may be it helps you to some extent.


Evaluation Order

In Java, the order of evaluation of operands in an expression is fixed. All operands are evaluated from left to right. The order of execution of the operations may be completely different. For example:


int [] a = {5, 5};
int b = 1;
a[b] = b = 10;
In this example, on line 3 the a[b] operand is evaluated to a[1] because at that moment b equaled 1. Next b is evaluated to 1 again. Finally, 10 is evaluated simply as the constant 10. After the operands are evaluated, the assignment operations take place. Assignment is a right to left operation, so b is assigned 10 and then a[1] is assigned the value of b, which is 10.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic