summaryrefslogtreecommitdiff
path: root/6p22.cpp
blob: 91f4bcdac647253793a84d46674eda7f8f063017 (plain)
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
#include <iostream>

/*
 *
 * 6.22
 *
 *
 */

void SwapIntPtr(int **p1, int **p2) {

	int *p1tmp = *p1;
	*p1 = *p2;
	*p2 = p1tmp;
}

void SwapIntPtrREF(int *&p1, int *&p2) {

	int *p1tmp = p1;
	p1 = p2;
	p2 = p1tmp;
}

int main () {
	
	int i1 = 10;
	int i2 = 21;
	int i3 = 13213;
	int i4 = 2331;
	int *p1 = &i1;
	int *p2 = &i2;
	int *p3 = &i3;
	int *p4 = &i4;
	std::cout << "p1 " << p1 << "\np2 " << p2 << std::endl;
	SwapIntPtr(&p1, &p2);
	std::cout << "p1 " << p1 << "\np2 " << p2 << std::endl;
	std::cout << "\np3 " << p3 << "\np4 " << p4 << std::endl;
	SwapIntPtrREF(p3, p4);
	std::cout << "p3 " << p3 << "\np4 " << p4 << std::endl;
	return 0;
}