##2021.10.3 ? ?周日
赋值运算符:
?
?代码演示:
#include<iostream>
using namespace std;
int main()
{
//赋值运算符
// =
int a = 10;
a = 100;//重新赋值
cout << "a = " << a << endl;
// +=
int b = 10;
b += 2;//本质是 b = b + 2
cout << b << endl;
/*输出结果为:12
-= 、 *= 、 /= 同理
/= 中,后面的数不能为零
*/
int c = 10;
c -= 2;
cout << c << endl; //8
int d = 10;
d *= 2;
cout << d << endl; //20
int e = 10;
e /= 2;
cout << e << endl; //5
// 模等于 %= 与上基本同样
int f = 10;
f %= 2;//本质是 a = a % 2
cout << f << endl;
//输出结果为:0
system("pause");
return 0;
}
END
|