-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCall.cpp
More file actions
49 lines (46 loc) · 1.17 KB
/
Copy pathCall.cpp
File metadata and controls
49 lines (46 loc) · 1.17 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
#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 a = "<<a<<endl;
cout<<"Before Swap using call by Value b = "<<b<<endl;
swap_V(a,b);
cout<<"After Swap using call by Value a = "<<a<<endl;
cout<<"After Swap using call by Value b = "<<b<<endl;
cout<<"Before Swap using call by Addres a = "<<a<<endl;
cout<<"Before Swap using call by Addres b = "<<b<<endl;
swap_A(&a,&b);
cout<<"After Swap using call by Addres a = "<<a<<endl;
cout<<"After Swap using call by Addres b = "<<b<<endl;
cout<<"Before Swap using call by Reference a = "<<a<<endl;
cout<<"Before Swap using call by Reference b = "<<b<<endl;
swap_R(a,b);
cout<<"After Swap using call by Reference a = "<<a<<endl;
cout<<"After Swap using call by Reference 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;
}