We have seen increment operator in C Programming which increments the value of the variable by 1. Similarly C Supports one more unary operator i.e decrement operator which behaves like increment operator but only difference is that it decreases the value of variable by 1.

Decrement Operator in C Programming :

  1. Decrement operator is used to decrease the current value of variable by subtracting integer 1.
  2. Like Increment operator, decrement operator can be applied to only variables.
  3. Decrement operator is denoted by -.

Different Types of Decrement Operation :

When decrement operator used in C Programming then it can be used as pre-decrement or post-decrement operator.

A. Pre Decrement Operator in C Programming :

Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression.

b = ++y;

In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before using it in a expression.

B. Post Increment Operator in C Programming :

Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented.

b = x++;

In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5 because old value of ‘x’ is used.

Live Program : C Program to Perform Increment Operation in C Programming

#include<stdio.h>
void main()
{
int a,b,x=10,y=10;
a = x++;
b = ++y;
printf("Value of a : %d",a);
printf("Value of b : %d",b);
}

Output :

Value of a : 10
Value of b : 11

Tip #1 : Increment Operator should not be used on Constants

We cannot use increment operator on the constant values because increment operator operates on only variables. It increments the value of the variable by 1 and stores the incremented value back to the variable,

b = ++5;

Or

b = 5++;

Summary : Expression Solving using Pre/Post Increment

When Postfix (++) is used with a variable in an Expression ,The Expression is evaluated first using the original value of variable and then variable is incremented by one