# Increment and Decrement Operator

Increment Operator will increment the value by 1. Types of Increment operator:

1. Pre-Increment
2. Post-Increment

Example 1: Post-Increment Operator.

``````#include<stdio.h>
void main()
{
int a=10;
a++;
printf("Value = %d",a);
}``````
Value = 11

Example 2: Pre-Increment Operator.

``````#include<stdio.h>
void main()
{
int a=10;
++a;
printf("Value = %d",a);
}``````
Value = 11

Example 3: Post-Decrement Operator.

``````#include<stdio.h>
void main()
{
int a=10;
a--;
printf("Value = %d",a);
}``````
Value = 9

Example 4: Pre-Decrement Operator.

``````#include<stdio.h>
void main()
{
int a=10;
--a;
printf("Value = %d",a);
}``````
Value = 9

Difference between Post-Increment and Pre-Increment Operator.

Example 5: Post-Increment Operator.

``````#include<stdio.h>
void main()
{
int a=10, b;
b = a++;
printf("A = %d\n",a);
printf("B = %d",b);
}``````
A = 11
B = 10

Example 6: Pre-Increment Operator.

``````#include<stdio.h>
void main()
{
int a=10, b;
b = ++a;
printf("A = %d\n",a);
printf("B = %d",b);
}``````
A = 11
B = 11

# Exercise on Increment and Decrement Operator

Exercise 1:
int x=1, y=2, z=3;
printf ("\n%d", x++ + ++y - --z);
Click for Ans: 2

Exercise 2:
int x=1, y=2, z=3;
printf ("\n%d", --x – y-- + z++);
Ans: 1

Exercise 3:
int x=1, y=2, z=3;
printf ("\n%d", x++ * ++y % ++z);
Ans: 3

Exercise 4:
int x=1, y=2, z=3;
printf ("\n%d", --x / --y * --z);
Ans: 0

Exercise 5:
int x=1, y=2, z=3;
printf ("\n%d", --x - z-- % --y);
Ans: 0

Exercise 6:
int x=1, y=2, z=3;
printf ("\n%d", --x - --y - --z);
Ans: -3

Exercise 7:
int x=1, y=2, z=3;
printf ("\n%d", ++x * y-- - ++y *x--);
Ans: 0

Exercise 8:
int x=10, y=11, z=12, w;
w = ++x – y++;
printf ("%d %d %d", w, x, y);
Ans: 0 11 12

Exercise 9:
int x=10, y=11, z=12, w;
w = ++y + x++ * z--;
printf ("%d %d %d %d", w, y, x, z);
Ans: 132 11 12 11

Exercise 10:
int x=10, y=11, z=12, w;
w = ++x % ++y % ++z;
printf ("%d %d %d %d", w, x, y, z);
Ans: 11 11 12 13

Exercise 11:
int x=10, y=11, z=12, w;
w = ++x / y--;
printf ("%d %d %d", w, x, y);
Ans: 1 11 10

Exercise 12:
int a=5, b=6, c=7, d=8;
x = a + b * c % d;
printf ("%d",x);
Ans: 7

Exercise 13:
int a=2, b=3, x;
x = a++ * b++ * a++ * b++;
printf ("%d",x);
Ans: 72

Exercise 14:
int a=2, b=3, x;
x = ++a * b-- * a++ * --b;
printf("%d",x);
Ans: 27