Increment and Decrement Operators in C
November 4, 2020
In C, there are two increment (++)
and decrement (--
) operators to change the value of an operand (constant or variable) by 1. Increment operator (++)
increases the value by 1 whereas decrement operator ( --
) decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.
Operator | Description | Example |
---|---|---|
++ | Increment | ++i,i++ |
— | Decrement | –i,i– |
C code with increment and decrement operators:
// increment and decrement operator #include <stdio.h> void main() { int i = 5; printf("++i = %d \n", ++i); printf("i++ = %d \n", i++); printf("--i = %d \n", --i); printf("i-- = %d \n", i--); printf("i = %d \n", i); }
Output:
++i = 6 i++ = 6 --i = 6 i-- = 6 i = 5
Click Operators in C to know other operators in C programming language.
In this tutorial, I have shown increment and decrement operators in C. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.