C++赋值运算符
目录
1、=、+=、-=、*=、/=、%=
2、代码以及结果
#include<iostream>
using namespace std;
int main() {
//赋值运算符
// =
int a = 10;
a = 100;
cout << "a=" << a << endl;
// +=
a = 10;
a += 2;
cout << "a=" << a << endl;
// -=
a = 10;
a -= 2;
cout << "a=" << a << endl;
// *=
a = 10;
a *= 2;
cout << "a=" << a << endl;
// /=
a = 10;
a /= 2;
cout << "a=" << a << endl;
// %=
a = 10;
a %= 2;
cout << "a=" << a << endl;
system("pause");
return 0;
}
a=100
a=12
a=8
a=20
a=5
a=0
请按任意键继续. . .