-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathref.cpp
More file actions
45 lines (38 loc) · 702 Bytes
/
ref.cpp
File metadata and controls
45 lines (38 loc) · 702 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
using namespace std;
int swap(int *a,int *b) {
int t;
t = *a;
*a = *b;
*b = t;
}
int swap1(int &a,int &b) {
int t;
t = a;
a = b;
b = t;
}
//int swap2(int &a,int &b) {
// int t;
// t = *a;
// *a = *b;
// *b = t;
//}
int main() {
int a = 10;
int b = 44;
cout << "original value\n";
cout << "a = "<< a << " b = "<< b << endl;
swap(a,b);
cout << "after swap\n";
cout << "a = "<< a << " b = "<< b << endl;
swap(&a,&b);
cout << "after swap\n";
cout << "a = "<< a << " b = "<< b << endl;
swap1(a,b);
cout << "after swap 1\n";
cout << "a = "<< a << " b = "<< b << endl;
//swap2(a,b);
//cout << "after swap 1\n";
//cout << "a = "<< a << " b = "<< b << endl;
}