Decrement Operators in C++
Below is the implementation of Decrement Operator in C++:
#include <iostream>
using namespace std;
int main()
{
int x = 5;
// Prefix decrement: decrement x by 1 and then print the
// value (4)
cout << --x << endl;
// Postfix decrement: print the value of x (4) and then
// decrement x by 1
cout << x-- << endl;
// Output: 3
cout << x << endl;
return 0;
}
Output
4 4 3
Increment and Decrement Operators in Programming
Increment and Decrement Operators are Unary Operators commonly used in programming to increase or decrease the value of a variable by one, respectively. They provide a shorthand way to perform these common operations.
Table of Content
- Increment Operators
- Increment Operators in C
- Increment Operators in C++
- Increment Operators in Java
- Increment Operators in Python
- Increment Operators in C#
- Increment Operators in Javascript
- Decrement Operators
- Decrement Operators in C
- Decrement Operators in C++
- Decrement Operators in Java
- Decrement Operators in Python
- Decrement Operators in C#
- Decrement Operators in Javascript
- Difference between Increment and Decrement Operator