Increment Decrement Operators in C | Increment operator in C | Decrement operators in C

Increment Decrement Operators in C | Increment operator in C | Decrement operator in C

1. Increment Operator in C (++)

Increment operator in   C is used to add 1 to the existing value of a variable.

It can be used in two ways:-

Prefix Form of increment operator in C

In prefix form of the increment operator ++ sign is placed before the operand. It adds one to the existing value of variable then takes the incremented value of variable .

Example: ++a.

Postfix Form of increment operator in C

In postfix form of increment operator ++ sign is placed after the operand. It adds one to the value of variable in next statement.

Example: a++.



2. Decrement Operator in C (–)

Decrement operator (–)  is used to subtract one from the existing value of a variable.

Prefix Form of decrement operator in C

In prefix form of  decrement operator — sign is placed before the operand. It subtracts one from the existing value of variable then takes the decremented value of variable.

Example: –a

Postfix Form of decrement operator in C

In postfix form of  decrement operator — sign is placed after the operand. It subtracts one from the existing value of variable in the next statement.

Example: a–

Program to demonstrate increment / decrement operator in C
#include<stdio.h>
int main()
{
int a=10;
printf("\n%d",++a);    /*11*/
printf("\na=%d",a++);  /*11*/
printf("\na=%d",a);    /*12*/
printf("\na=%d",a--);  /*12*/
printf("\na=%d",--a); /*10*/
return (0);
}

 


Spread the love
Lesson tags: decrement operator in c, increment operators in C, postfix form of decrement operator, postfix form of increment operator, prefix form of decrement operator, prefix form of increment operator
Back to: C Programming Language
Spread the love