-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreference.cpp
More file actions
61 lines (50 loc) · 1.14 KB
/
reference.cpp
File metadata and controls
61 lines (50 loc) · 1.14 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
using namespace std;
void swap_v(int,int);
void swap_a(int*,int*);
void swap_r(int&,int&);
int main()
{
int a = 10,b=20;
cout << "Before swap using call by value" << endl;
cout << "a = " << a << endl << "b = " << b << endl;
swap_v(a,b);
cout << "After swap using call by value" << endl;
cout << "a = " << a << endl << "b = " << b << endl;
a=10;
b=20;
cout << "Before swap using call by address" << endl;
cout << "a = " << a << endl << "b = " << b << endl;
swap_a(&a,&b);
cout << "After swap using call by address" << endl;
cout << "a = " << a << endl << "b = " << b << endl;
a=10;
b=20;
cout << "Before swap using call by reference" << endl;
cout << "a = " << a << endl << "b = " << b << endl;
swap_r(a,b);
cout << "After swap using call by reference" << endl;
cout << "a = " << a << endl << "b = " << b << endl;
return 0;
}
void swap_v(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
}
void swap_a(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void swap_r(int &x, int &y)
{
int temp;
temp = x;
x = y;
y = temp;
}