运算符:
1. 算术运算符:
两个整数相除结果仍是整数(小数部分去掉)
除数为0会报错
#include<iostream>
using namespace std;
int main()
{
//1、前置递增,先加1再运算
//2、后置递增,先运算后加1
int b = 10;
int c = ++b * 10;
cout << b << endl;//11
cout << c << endl;//110
int d = 10;
int e = d++ * 10;
cout << d << endl;//11
cout << e << endl;//100
system("pause");
return 0;
}
2. 赋值运算符
#include<iostream>
using namespace std;
int main()
{
// =
int a = 10;
cout << "a=" << a<<endl;
// +=
a += 2;
cout << "a=" << a << endl;
// -=
a -= 2;
cout << "a=" << a << endl;
// *=
a *= 2;
cout << "a=" << a << endl;
// /=
a /= 2;
cout << "a=" << a << endl;
// %=
a %= 2;
cout << "a=" << a << endl;
system("pause");
return 0;
}