-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex30.cpp
More file actions
44 lines (34 loc) · 731 Bytes
/
Copy pathex30.cpp
File metadata and controls
44 lines (34 loc) · 731 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
/*
CPSC 121-0X
Paul De Palma
depalma
Example 30
*/
//reference variables
#include <iostream>
using namespace std;
void shift(int&,int&);
int main()
{
int var1 = 10, var2 = 20;
cout << "variable var1 holds " << var1 << endl;
cout << "variable vari2 holds " << var2 << endl;
shift(var1,var2);
cout << "Returned from function" << endl;
cout << "variable var1 holds " << var1 << endl;
cout << "variable vari2 holds " << var2 << endl;
return 0;
}
/*
Pre: Both parameters are reference variables whose source has been
initialized
Post: The variables referred to by the parameters have their values
exchanged
*/
void shift(int& var1, int& var2)
{
int buf;
buf = var1;
var1 = var2;
var2 = buf;
}