OPERATOR PRECEDENCE

Definition:

When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence. Parentheses can be used to override the order of precedence and force some parts of an expression to be evaluated before other parts.

Operators are evaluated in a well defined order

  • Parentheses can be used to override the order of precedence and force some parts of an expression to be evaluated before other parts.
  • Operations within parentheses are always performed before those outside.
  • Within  parentheses, however, normal operator precedence is maintained.
Following are the operators that are applicable in a particular order either Left to Right or Right to Left.



  • When expressions contain operators from more than one category, arithmetic operators are evaluated first, comparison operators are evaluated next, and logical operators are evaluated last.
  • Comparison operators all have equal precedence i.e., they are evaluated in the left-to-right order in which they appear.
Example:



Previous
« Prev Post