Increment Decrement Operators in C (++ / –)

Preview

1. Increment Operator

It is represented as (++). It adds one to existing value of a variable. There are two ways to use it.

Prefix Form

In this type, increment operator is fixed before the variable name. It immediately adds one to the existing value of variable .

Example: ++a.

Postfix Form

In this type, the increment operator is fixed after variable name. It adds one to the value of variable in the next step.

Example: a++.



2. Decrement Operator

it is represented as –. It subtracts one from the present value of a variable.

Prefix Form

In this type, decrement operator is fixed before the variable name. It immediately subtracts one from the existing value of variable .

Example: –a

Postfix Form

In this type, the decrement operator is fixed after variable name. It subtracts one from the value of variable in the next step.

Example: a–

Program to demonstrate increment / decrement operator. Output (Line Wise)
#include<stdio.h>
int main()
{
int a=10;

 

 

printf(“\na=%d”,++a); a=11
printf(“\na=%d”,a++); a=11
printf(“\na=%d”,a); a=12
printf(“\na=%d”,a–); a=12
printf(“\na=%d”,–a); a=10
return (0);
}

 



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