Increment and Decrement operators

By | March 27, 2018

Increment and Decrement operators in C-: C language providing very useful two operators these are the Increment and Decrement operators. These are different type operator. Increment operator increase the value and decrement operator decrease the value.

  1. First is the increment operator(++ )-:  it adds one (1) in the value and  its called the increment operator.
  2.  second is the decrement operator (–) it subtract  1 and  its called the decrement operator.

we used these operators as like v++ or ++v  and v– or –v these are two way we can use these operators.

Increment operator in c programming  -:  In this operator increase the value one. It is the increasing the value one by one when the condition becomes false. we can write this operator as like (v++) this condition called the post increment condition and  (++v)  this is called the pre increment condition. For example 

if(v=0; v=>10; v++;)

In this example v is variable name and v value start with 0 and maximum value of 10. Its print the value of v when the condition becomes false.

Decrement Operator in c programming language -: This is decrease the value one. It is decreasing the value one by one when the condition becomes false. we can write this operator as like (v–) this condition called the post decrement condition and or (–v) this condition called the pre decrement condition. for example 

if(v=10; v=>0; v--;)

In this example v is variable name and v value start with 10 and minimum value of 0. Its print the value of v when the condition becomes false.

There are some rules for using these operators

  1. Increment and Decrements operators are unary operators and they require variable
  2. when we use increment or decrements is used with a variable in an expression, the expression is evaluated first using original variable value after then variable is increment or decrement
  3. these are same unary + or unary -.

 

Increment operator example in c programming language 

#include<stdio.h>
#include<conio.h>

void main()
{
int v;

int i;


i=5;


v=++i;


printf("After using increment operator value is : %d",v);


printf("After using increment operator value is : %d",i);


getch();

}

 

The output of this program -:

After using increment operator value is :6

After using increment operator value is :6

Another example of increment operator printing the number

#include<stdio.h>
#include<conio.h>

void main()
{
int v;

If(v=0; v=>10; v++;)

{

printf("The number values are : %d",v);


}


getch();


}

 

The output of this program-:

The number values are : 1 2 3 4 5 6 7 8 9 10

 

Decrements operator in c programming language-:

#include<stdio.h>
#include<conio.h>

void main()
{
int v;

int i;


i=5;


v=--i;


printf("After using decrement operator value is : %d",v);


printf("After using decrement operator value is : %d",i);


getch();

}

The output of this program-:

After using decrement operator value is :4

After using decrement operator value is :4

Another example of decrement operator printing the number-:

#include<stdio.h>
#include<conio.h>

void main()
{
int v;

If(v=10; v=>10; v--;)

{

printf("The number values are : %d",v);


}


getch();


}

The output of this program

The number values are : 10 9 8 7 6 5 4 3 2 1 0

 

Read More about c programming operators 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *