Showing posts with label --). Show all posts
Showing posts with label --). Show all posts

Wednesday, January 27, 2016

Increment and Decrement operators ( ++, --)

There are two special arithmetic operators called increment and decrement operators available C. They are unary operators unlike all other arithmetic operators. The operators are denoted as : '++' (increment operator), '--' (decrement operator).
OperatorNameDescriptionExample
++Increment OperatorIncrements the value of operand by 1a++ : This is equivalent to a = a + 1
--Decrement OperatorDecrements the value of operand by 1a-- : This is equivalent to a = a - 1

Variants of Increment and Decrement Operators - Pre Increment, Post Increment, Pre Decrement and Post Decrement

There are two different variants of increment and decrement operators known as pre increment, post increment, pre decrement and post decrement operators.
  • Pre Increment Operators: When '++' is used as prefix of the operand, it's called pre increment operator. Pre increment operator will increment the value of operand before using it in the expression.
  • Post Increment Operators: When '++' is used as postfix of the operand, it's called post increment operator. Post increment operator will increment the value of operand after using it in the expression. ie; The current expression will use non-incremented value of operand.