Increment and Decrement Operators

Increment and Decrement operators are used to increase or decrease the value of a variable.

Increment operator :

Increment operators are the unary operators which are used to increase the operand value.

Increment operators has two types

1. Pre-increment operator

The pre-increment operator is used to increase the value of the operand before assigning it to the expression.

2. Post-increment operator

The post-increment operator is used to increase the value of the operand after assigning it to the expression.

Decrement operator :

Decrement operators are the unary operators which are used to decrease the operand value.

Decrement operators has two types

1. Pre-decrement operator

The pre-decrement operator is used to decrease the value of the operand before assigning it to the expression.

2. Post-decrement operator

The post-decrement operator is used to decrease the value of the operand after assigning it to the expression.

The Increment and Decrement operators are :

++ Increment operator
-- Decrement operator

Increment and Decrement operations program

        
#include <stdio.h>

int main()
{
    int a = 5;

    //Pre-increment
    ++a;
    printf("Pre-increment : %d\n", a);

    //Post-increment
    a++;
    printf("Post-increment : %d\n", a);

    //Pre-decrement
    --a;
    printf("Pre-decrement : %d\n", a);

    //Post-decrement
    a--;
    printf("Post-decrement : %d\n", a);

    return 0;
}
        
    

Output

        
Pre-increment : 6
Post-increment : 7
Pre-decrement : 6
Post-decrement : 5
        
    

Post a Comment

0 Comments