-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Operators Assignment Operators.cpp
More file actions
68 lines (47 loc) · 2.38 KB
/
C++ Operators Assignment Operators.cpp
File metadata and controls
68 lines (47 loc) · 2.38 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
/**
: c++
[PROG] : Assignment Operators
[AUTHOR] : Saddam Arbaa <saddamarbaas@gmail.com> */
#include <iostream>
using namespace std;
int main()
{
//A list of all assignment operators
int num = 21 ; // declare variable name num and assign value 23
int result; // declare variable name result
result = num; // result = now 23
cout << "line 1- = operator ,value of result = :" <<result<< endl;
result += num;
cout << "line 2- += operator ,value of result = :" <<result<< endl;
result -= num;
cout << "line 3- -= operator ,value of result = :" <<result<< endl;
result *= num;
cout << "line 4- *= operator ,value of result = :" <<result<< endl;
result /= num;
cout << "line 5- /= operator ,value of result = :" <<result<< endl;
result = 200; // result is now 200
result %= num; //% Returns the division remainder
cout << "line 6- %= operator ,value of result = :" <<result<< endl;
result = 1; // result right now is 00000001
result = result << 3; // Left shifting it by 3 will make it 00001000, ie, 8
cout << "line 7- <<= operator ,value of result = :" <<result<< endl;
result = result >> 2; // Right shifting a by 2 will make it 00000010, ie, 2
cout << "line 8- >>= operator ,value of result = :" <<result<< endl;
result = 37; //result right now is 37 00100101
result &= 23; // result & with 23 which is 00010111
// new result value is 5 with 00000101
cout << "line 10- &= operator ,value of result = :" <<result<< endl;
result = 37; //result right now 37 00100101
result |= 23; // result | with 23 which is 00010111
// new result value is 55 with 00110111
cout << "line 11- |= operator ,value of result = :" <<result<< endl;
result = 37; // 00100101. ~37 is then 11011010
result = ~result;
cout << "line 12- ~= operator ,value of result = :" <<result<< endl;
result = 5; //result right now is 5 00000101
result ^= 3; // result ^ with 3 which is 00000011
// result & 3 value first is 00000001
// final result is 6 is 00000110
cout << "line 13- ^= operator ,value of result = :" <<result<< endl;
return 0;
}