Increment & Decrement Operator

Card image cap

Increment Operator ?

Increment operators are used to increase the value of the variable by one. The increment operator ++ adds 1 to its operand,

Syntax:

  ++ // increment operator

Decrement Operator ?

Decrement operators are used to decrement the value of the variable by one. The decrement operator -- subtracts 1 to its operand,

Syntax:

  -- // decrement operator

Both increment and decrement operator are used on single operand or variable, so it is called as unary operator.

Unary operators are having higher priority than the other operators it means unary operators are execute before other operators


Card image cap

Increment and Decrement Operators

Operator Description Example
++ Post Increment a++
-- Post Decrement a--
++a Pre Increment ++a
--a Pre Decrement --b

Card image cap

Example 1:



Output :

    x: 11
    i: 11
Card image cap

Example 2:



Output :

  x: 10
  i: 9
Card image cap

Example 3:



Output :

  Result 1 - Value of a++ is :21
  Result 2 - Value of a is :22
  Result 3 - Value of ++a is  :23
Card image cap