Increment operator (++)
The increment operator (++) increases the value of a variable by 1. It is mostly used inside a loop to increment the loop counter. Syntax of increment operator is below:
int number = 0;
number++;
number++ will increase the value of a variable number by 1.
Decrement operator (--)
The decrement operator (--) decreases the value of the variable by 1. It is also used in the loop when we need to decrement loop counter by 1 in each loop iteration. Syntax of decrement operator is below:
int number = 1;
number--;
number-- will decrease the value of a variable number by 1.
Both operators are unary operators as both work on only one operand.
C++ Program to use increment and decrement operators:
Output
Post a Comment