What are the rules for ++ and -- operators?

Rules for ++ and – operators: 

Following are the rules for the increment (++) and decrement (--) operators.


  1. Increment (++) and decrement (--) operators are unary operators and they require variable as their operands.
  2. When postfix ++ (or --) is used with a variable in an expression, the expression is evaluated first using the original value of the variable and then the variable is incremented (or decremented) by one.
  3. When prefix ++ (or --) is used in an expression, the variable is incremented (or decremented) first and then the expression is evaluated using the new value of the variable.
The precedence and associatively of ++ and --operators are the same as those of unary + and unary -.

Author: Tanmay Chakrabarty

Tanmay Chakrabarty is a former CSE student, currently working as a Senior Software Engineer with 5+ years of experience in the field of Web Application development in PHP+MySQL platform with strong skills in Javascript, JQuery, JQuery UI and CSS. He tries to write notes every week but fails due to heavy loads of duty.

Recommended Recommends

Comments

Contact Us