-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointerTasks.cpp
More file actions
95 lines (76 loc) · 1.39 KB
/
Copy pathpointerTasks.cpp
File metadata and controls
95 lines (76 loc) · 1.39 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
using namespace std;
void noNegatives(int *x) {
if(*x < 0){
*x = 0;
}
}
int temp;
void swap(int &x, int &y) {
int temp = x;
x = y;
y = temp;
}
const int size = 2;
int main() {
int x, y;
int* p1;
p1 = &x;
*p1 = 99;
cout << "Steps 5 & 6" << endl;
cout << x << endl;
cout << *p1 << endl;
p1 = &y;
*p1 = -300;
cout << "Step 7 & 8" << endl;
cout << y << endl;
int temp;
int* p2;
p2 = &x;
temp = *p1;
*p1 = *p2;
*p2 = temp;
cout << "Step 9 & 10" << endl;
cout << *p1 << endl;
cout << *p2 << endl;
cout << x << endl;
cout << y << endl;
cout << "Steps 11 & 12" << endl;
noNegatives(&x);
cout << x << endl;
noNegatives(&y);
cout << y << endl;
cout << "Step 13" << endl;
p2 = &x;
cout << x << endl;
p2 = &y;
cout << y << endl;
int a[size];
p2 = &x;
a[0] = *p2;
p2 = &y;
a[1] = *p2;
cout << "Steps 14-18" << endl;
cout << a[0] << endl;
cout << a[1] << endl;
cout << "Steps 19 & 20" << endl;
cout << a[0] << endl;
cout << a[1] << endl;
p1 = &a[0];
p2 = &a[1];
temp = *p1;
*p1 = *p2;
*p2 = temp;
a[0] = *p1;
a[1] = *p2;
cout << a[0] << endl;
cout << a[1] << endl;
cout << "Steps 21 & 22" << endl;
swap(x, y);
cout << x << endl;
cout << y << endl;
cout << "Step 23" << endl;
swap(a[0], a[1]);
cout << a[0] << endl;
cout << a[1] << endl;
}