-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path05_Operands_Operators.cpp
More file actions
68 lines (52 loc) · 1.02 KB
/
05_Operands_Operators.cpp
File metadata and controls
68 lines (52 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
/*
Operators in C++:
assignment: = => number = 5;
----------------------------
arithmetic:
- + * / % ++ --
Example: -4, a+b, a*b
Suppose: int a = 3;, int b = 2;
a = a\b; => a is updated with 1 (a = 1)
a++; => a is updated with 2 (a = 2)
a--; => a is updated with 1 (a = 1)
----------------------------
shorthand assignment:
+= -= *= /= %=
a+=b; => a = a + b;
a*=b; => a = a * b;
----------------------------
logical:
|| => or
&& => and
*/
/*
Order of operator precedence:
1) ()
2) *, /, %
3) +, -
Operations of the same precedence are conventionally evaluated from LEFT to RIGHT.
Example:
a + ((c-b)*d) + a/d
(1)
(2)
(3)
(4)
(5)
*/
int main(){
int a = 4;
int b = -4;
//a = a * b;
a *= b;
cout << a << endl;
a /= b;
cout << a << endl;
a += b;
cout << a << endl;
a++;
cout << a << endl;
a--;
cout << a << endl;
}