作用:用于将表达式的值赋给变量
赋值运算符包括以下几个符号
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
int main()
{
//=
int a = 10;
a = 100; //变量a重新赋值为100
cout << "a=" << a << "\n" << endl;
//+=
a = 10; //a重新赋值为10
a += 2;
cout << "a=" << a << "\n" << endl;
//-=
a = 10;
a -= 2;
cout << "a=" << a << "\n" << endl;
//*=
a = 10;
a *= 2;
cout << "a=" << a << "\n" << endl;
///=
a = 10;
a /= 2;
cout << "a=" << a << "\n" << endl;
system("pause");
return 0;
}
运行结果:
a=100
a=12
a=8
a=20
a=5