Increase and Decrease
Increase and Decrease
int main(){
//Increase Operators
//Pre-Increase (++)
int x;
x = 20;
cout << "x: " << x << endl;//x: 20
cout << "x: " << ++x << endl;//x: 21
cout << "x: " << x << endl;//x: 21
return 0;
}
Output:
int main(){
//Increase Operators
//Post-Increase (++)
int x;
x = 20;
cout << "x: " << x << endl;//x: 20
cout << "x: " << x++ << endl;//x: 20
cout << "x: " << x << endl;//x: 21
return 0;
}
Output:
int main(){
//Decrease Operators
//Pre-Decrease (--)
int x;
x = 20;
cout << "x: " << x << endl;//x: 20
cout << "x: " << --x << endl;//x: 19
cout << "x: " << --x << endl;//x: 18
cout << "x: " << x << endl;//x: 18
return 0;
}
Output:
int main(){
//Decrease Operators
//Post-Decrease (--)
int x;
x = 20;
cout << "x: " << x << endl;//x: 20
cout << "x: " << x-- << endl;//x: 20
cout << "x: " << x-- << endl;//x: 19
cout << "x: " << x << endl;//x: 18
return 0;
}
Output: