Increment Operators in C | Pre increment and Post Increment operators in C Language

Spread the love

Increment Operators in C Language:

  • The Increment Operators – Increments the Value of the variable by 1( by adding 1 to it’s Current Value ).
  • Increment Operator is an Unary operator. That means Increment operator is operates on only one Operand.
  • Increment Operator have Highest priority than all Binary Operators. Because Unary operators have higher priority than Binary operators. You can see Full priority table here C operators Priority table.
  • Increment Operator won’t work on Constants. It can be apply only on Variables.
  • Increment Operator Denoted by ++ Symbol.
  • Ex : ++X  or X++.

Different Types of Increment operators in C :

We have two types of Increment operators those are
  1. pre-increment operator (or) prefix increment operator.
  2. post-increment operator (or) postfix increment operator.

Pre-incremet Operator :

  • In pre-increment operator, Operator is written before the operand.
  • Pre-increment operator Increments the value of variable first, then incremented value is used to evaluate the Expression.
  1.  a= 5;
  2.  y = ++a;
In above example y value will be 6. because a value is first incremented then it will assigned to y. so y value is 6.

Post-Increment Operator :

  • In post-increment operator, Operator is written after the Operand.
  • Post-increment operator first expression is Evaluated and then value of Variable is Incremented. that means Incremented value is not used in expression.
  1.  a= 5;
  2.  y = a++;
In above example, The y value is 5. because in post increment operator value first assigned and then Incremented so value of y is 5. But value of a will becomes 6 after evaluating the expression.

Example program 1 : C program to Understand Increment operators

  1. #include<stdio.h>
  2. int main(void)
  3. {
  4.         int x=8,y=10;
  5.         printf(“x=%dt,x);
  6.         printf(“x=%dt,++x);   /*Prefix increment*/
  7.         printf(“x=%dt,x);
  9.         printf(“y=%dt,y);
  10.         printf(“y=%dt,y++);   /*Postfix increment*/
  11.         printf(“y=%dt,y);
  12.         return 0;
  13. }

Program Output :

Example 2 : program to understand Increment Operator in C

  1. #include<stdio.h>
  2. void main()
  3. {
  4. int a,b,c=5,d=5;
  5. = c++;
  6. = ++d;
  7. printf(“Value of a : %d”,a);
  8. printf(“Value of b : %d”,b);
  9. printf(“Value of c : %d”,c);
  10. printf(“Value of d : %d”,d);
  11. }

Program Output :

Example 3 : Increment Operators can not be used on Constants

  1. #include<stdio.h>
  2. void main()
  3. {
  4.         int a;
  5.         a = 10++;
  6. }

Program Output :

Compilation error time: 0 memory: 2248 signal:0

So it is clear that we can not use constants in increment operators.

Also Read :


Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

5 Responses

  1. Increase value vs address

    Increase value vs address


    int main(void)
    int *p, j;

    p = &j;

    j = 1;
    printf("%p ", p);

    (*p)++; /* now j is incremented and p is unchanged */
    printf("%d %p", j, p);

    return 0;

  1. […] Increment Operator and Pre and post Increments […]

  2. […] Increment Operator and Pre and post Increments […]

  3. […] have discussed the increment operators in our previous article, Here is another example to demonstrate the functionality of the Pre […]

  4. […] our previous article, We have discussed the Increment Operators in the C language. In today’s article, We are going to look into the Decrement operators in C language and […]

Leave a Reply