Showing posts with label 9.1.8 Increment/Decrements operators. Show all posts
Showing posts with label 9.1.8 Increment/Decrements operators. Show all posts

Wednesday, August 26, 2020

9.1.8 Increment/Decrements operators

  • You can use increment / decrements operators to increase or decrease the value of any variable instantly by a number. 
  • These are being given below.

Operators

 

Description

 

 

 ++ (increment)

This is a unary operator. 

It increases the value of the operand by a number.

When it seems before the operand, the value is increment first

and is used later.

When this operator operates after operand, the increment after the value of the operand is used.

 

 

 --(decrements)

This is also a unary operator.

This decreases the value of the operand by one number.

When it is used before the operand, the value decreases before the value is used.

When it is used after the variable,

the value is first used and later decreases.


EXAMPLE :-


// Increment and Decrement operators in C.
#include <stdio.h>
int main()
{
int p = 20, q = 50;
float r = 20.5, s = 50.5;

printf("++p is = %d \n", ++p);
printf("--q is = %d \n", --q);
printf("++r is = %f \n", ++r);
printf("--s is = %f \n", --s);

return 0;
}


OUTPUT


++p is = 21 --q is = 49 ++r is = 21.500000 --s is = 49.500000