Increment Operator

Increment operator in c language is used to increase variable value. It will increase one value in variable. We use ++ with variable to increase value.

Types of Increment Operator

There are two types of Increment Operators:-



Example of Increment Operator

In the following example, we are using both pre and post increment operator. First pre increment will be performed. After pre increment x value would be 11. After that sum will be performed. Sum will be 33 initially. After that two times post increment will be performed then x value would be 13 and y value will be 35.


#include<stdio.h>
void main()
{
    int x=10;
    int y;

    y=++x + x++ + x++;
    printf("Y is %d",y);
    printf("\nX is %d",x);
}


		
		increment operator
		Figure 1
		
		

Decrement Operator

Decrement operator in c language is used to decrease variable value. It will decrease one value in variable. We use -- with variable to increase value.

Types of Decrement Operator

There are two types of Decrement Operators:-



Example of Decrement Operator

In the following example, we are using both pre and post Decrement operator. First pre Decrement will be performed. After pre increment x value would be nine. After that sum will be performed. Sum will be 27 initially. After that two times post Decrement will be performed, then x value would be seven and y value will be 25.

		
		#include<stdio.h>
void main()
{
    int x=10;
    int y;

    y=--x + x-- + x--;
    printf("Y is %d",y);
    printf("\nX is %d",x);
}

		
		
		
		decrement operator
		Figure 2