forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.22.cpp
More file actions
28 lines (24 loc) · 685 Bytes
/
Copy path6.22.cpp
File metadata and controls
28 lines (24 loc) · 685 Bytes
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
#include <iostream>
void swapIntPtr(int **pa, int **pb) {
int *tmp = *pa;
*pa = *pb;
*pb = tmp;
}
void swapIntPtr(int *&pa, int *&pb) {
int *tmp = pa;
pa = pb;
pb = tmp;
}
int main() {
int i = 1, j = 2;
int *pi = &i, *pj = &j;
std::cout << "pi = " << pi << " *pi = " << *pi << std::endl;
std::cout << "pj = " << pj << " *pj = " << *pj << std::endl;
swapIntPtr(&pi, &pj);
std::cout << "pi = " << pi << " *pi = " << *pi << std::endl;
std::cout << "pj = " << pj << " *pj = " << *pj << std::endl;
swapIntPtr(pi, pj);
std::cout << "pi = " << pi << " *pi = " << *pi << std::endl;
std::cout << "pj = " << pj << " *pj = " << *pj << std::endl;
return 0;
}