Operators
Effect **: ** code for performing arithmetic
| Operator Type ** ** | ** action ** |
| -------------- | ------------------- ------------------- |
| arithmetic operators | four arithmetic operations for processing |
| assignment operator | expression for the value assigned to the variable |
| comparison operation Fu | expressions for comparison, and returns a true or false value |
| logical operators | return to true or false value according to the expression value |
Arithmetic Operators
** ** effect: four arithmetic operations for processing
Arithmetic modulo
. 1 #include <the iostream>
2 the using namespace STD;
. 3
. 4 int main () {
. 5
. 6 int A1 = 10 ;
. 7 int B1 = . 3 ;
. 8
. 9 COUT A1 + B1 << << endl;
10 COUT << A1 - B1 << endl;
. 11 COUT A1 * B1 << << endl;
12 is COUT << A1 / B1 << endl; // two integer division result remains an integer of
13 is
14 int A2 = 10 ;
15 int B2 = 20 is;
16 COUT << A2 / B2 << endl;
. 17
18 is int A3 = 10 ;
. 19 int B3 = 0 ;
20 is // COUT << A3 / B3 << endl; // error, the divisor can not be 0
21 is
22 is
23 is / / two decimal division can
24 Double D1 = 0.5 ;
25 Double D2 = 0.25 ;
26 is COUT << D1 / D2 << endl;
27
28 System ( " PAUSE " );
29
30 return 0;
31 }
1 int main() {
2
3 int a1 = 10;
4 int b1 = 3;
5
6 cout << 10 % 3 << endl;
7
8 int a2 = 10;
9 int b2 = 20;
10
11 cout << a2 % b2 << endl;
12
13 int a3 = 10;
14 int b3 = 0;
15
16 //cout << a3 % b3 << endl; //取模运算时,除数也不能为0
17
18 //两个小数不可以取模
19 double d1 = 3.14;
20 double d2 = 1.1;
21
22 //cout << d1 % d2 << endl;
23
24 system("pause");
25
26 return 0;
27 }
递增
1 int main() {
2
3 //后置递增
4 int a = 10;
5 a++; //等价于a = a + 1
6 cout << a << endl; // 11
7
8 //前置递增
9 int b = 10;
10 ++b;
11 cout << b << endl; // 11
12
13 //区别
14 //前置递增先对变量进行++,再计算表达式
15 int a2 = 10;
16 int b2 = ++a2 * 10;
17 cout << b2 << endl;
18
19 //后置递增先计算表达式,后对变量进行++
20 int a3 = 10;
21 int b3 = a3++ * 10;
22 cout << b3 << endl;
23
24 system("pause");
25
26 return 0;
27 }