increment and decrement Operator in c

12 Aug 2022 Balmiki Mandal 0 C Programming

Increment and Decrement Operators

The increment operator will increment the operand by one value similarly decrements operator decrement the operand by 1 value. This operator will modify the operand so we need to pass only variables constants are not allowed

  • --     
  • ++
  • These two-operator are unary operator

These operators are divided into two category

  1. Prefix Increment/decrement-operator is written before the operand.(++num, --num)
  2. Postfix Increment/decrement - operator is written after the operand(num++,num--)


Pre increment/ decrement operator:

in pre-increment first increment then assign it.

Example

#include<stdio.h>
int main()
{
int i=10;
printf("i=%d\n",i);
++i;
//--i;
//++10; error
printf("i=%d\n",i);
}
 

Post increment and decrement:

Post increment rule is first assigned and then increment or decrement of the operand.

Example: 

#include<stdio.h>
void main()
{
//int i=10;
volatile int i=10;
printf("i=%d\n",i);
printf("%d %d %d\n",i++,i++,i++,i++);
}

Output:

using volatile: 14,13,12,11
not using voltaile: 14,14,14,14
in case of pre increment no increment case the latest value will assign gets update

Top Resources

Arithmetic operator in c

Assignment operator in c programming

Relational operator in c programming

Logical Operator in c programming

Bitwise operator in c programming

sizeof operator in c programming

Understanding the Comma Operator in C Programming

Dot Operator in c programming

Using && Logical AND Operator in C Programming

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.