Increment Operators: The increment operator is used to increment the value of
a variable in an expression. In the Pre-Increment, value is first incremented
and then used inside the expression. Whereas in the Post-Increment, value is
first used inside the expression and then incremented.
Decrement Operators: The decrement operator is used to decrement the value of
a variable in an expression. In the Pre-Decrement, value is first decremented
and then used inside the expression. Whereas in the Post-Decrement, value is
first used inside the expression and then decremented.
i++ i-- ++i --i
Example Name Effect
---------------------------------------------------------------------
++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one.
--$a Pre-decrement Decrements $a by one, then returns $a.
$a-- Post-decrement Returns $a, then decrements $a by one.
// Working of increment and decrement operators
#include <iostream>
using namespace std;
int main() {
int a = 10, b = 100, result_a, result_b;
// incrementing a by 1 and storing the result in result_a
result_a = ++a;
cout << "result_a = " << result_a << endl;
// decrementing b by 1 and storing the result in result_b
result_b = --b;
cout << "result_b = " << result_b << endl;
return 0;
}