C++ លំហាត់ Increase and Decrease Operators
1. Increase Operators (++): កំណ ើន
1.1. Pre-Increase Operators: ណកន
ើ មុន
C++ Code:
#include<iostream>
using namespace std;
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:
1.2. Post-Increase Operators: ណកន
ើ ណរោយ
C++ Code:
#include<iostream>
using namespace std;
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:
2. Decrease Operators (--): ថយ
2.1. Pre-Decrease Operators: ថយមុន
C++ Code:
#include<iostream>
using namespace std;
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:
2.2. Post-Decrease Operators: ថយតាមណរោយ
C++ Code:
#include<iostream>
using namespace std;
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: