-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path案例1.cpp
More file actions
36 lines (35 loc) · 721 Bytes
/
Copy path案例1.cpp
File metadata and controls
36 lines (35 loc) · 721 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
#include <iostream>
using namespace std;
void SwapValue(int a, int b)
{
int tmp;
tmp = a;
a = b;
b = tmp;
cout << "在SwapValue()中a=" << a << ",b=" << b << endl
<< endl;
}
void SwapRef(int &m, int &n)
{
int tmp;
tmp = m;
m = n;
n = tmp;
cout << "在SwapRef()中m=" << m << ",n=" << n << endl
<< endl;
}
int main()
{
int a = 10, b = 20;
cout << "数据变换前:\t\ta=" << a << ",b=" << b << endl
<< endl;
SwapValue(a, b);
cout << "调用SwapValue()后:\t\ta=" << a << ",b=" << b << endl
<< endl;
a = 10;
b = 20;
SwapRef(a, b);
cout << "调用SwapRef()后:\t\ta=" << a << ",b=" << b << endl
<< endl;
return 0;
}