-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticep18.cpp
More file actions
53 lines (40 loc) · 1.08 KB
/
practicep18.cpp
File metadata and controls
53 lines (40 loc) · 1.08 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
#include <iostream>
using namespace std;
//function call by value
void swapByValue(int a, int b) {
int temp = a;
a = b;
b = temp;
cout << "Inside swapByValue function: " << endl;
cout << "a = " << a << ", b = " << b << endl;
};
//function call by references
void swapByRef(int& a, int& b) {
int temp = a;
a = b;
b = temp;
cout << "Inside swapByRef function: " << endl;
cout << "a = " << a << ", b = " << b << endl;
};
//function call by pointer/address
void swapByPointer(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
cout << "Inside swapByPointer function: " << endl;
cout << "a = " << *a << ", b = " << *b << endl;
};
int main(){
int x = 10, y = 20;
cout << "Before swapping: " << endl;
cout << "x = " << x << ", y = " << y << endl;
//call by value
swapByValue(x, y);
//call by reference
swapByRef(x, y);
//call by pointer/address
swapByPointer(&x, &y);
cout << "After swapping: " << endl;
cout << "x = " << x << ", y = " << y << endl;
return 0;
}