Home →C Programming Language →C Operators
C Increment Operators
We can use increment operator to increase or decrease the value of variable. C increment operators support in both prefix and postfix form. Here are syntax of of increment operators:
variable++; variable--; ++variable; --variable;
Here is demonstration program:
#include <stdio.h>
/* a program demonstrates C increment operators */
void main(){
int x = 10;
int y = 0;
printf("x = %d\n",x);
/* demonstrate ++ prefix operator */
y = ++x;
printf("y = ++x;y = %d\n",y);
/* demonstrate ++ postfix operator */
y = x++;
printf("y = x++;y = %d\n",y);
/* demonstrate -- prefix operator */
y = --x;
printf("y = --x;y = %d\n",y);
/* demonstrate -- postfix operator */
y = x--;
printf("y = x--;y = %d\n",y);
/* keep console screen until a key stroke */
char key;
scanf(&key);
}
And the output is:
x = 10 y = ++x;y = 11 y = x++;y = 11 y = --x;y = 11 y = x--;y = 11
