how to use decrement operator in c++
#include <iostream>
using namespace std;
int main() {
int num = 5;
cout << "Original value of num: " << num << endl;
num--; // Using the decrement operator
cout << "Value of num after decrement: " << num << endl;
return 0;
}
Explanation:
- Declare an integer variable num
and assign it the value 5
.
- Print the original value of num
.
- Use the decrement operator --
on num
, reducing its value by 1.
- Print the updated value of num
after decrementing.