-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17.cpp
49 lines (40 loc) · 886 Bytes
/
17.cpp
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(int a, int b)
{
int temp = a;
a = b;
b = temp;
}
int main()
{
int a = 4, b = 5;
cout << "Value of a is " << a << "and value of b is " << b << endl;
swap(a, b);
cout << "Value of a is " << a << "and value of b is " << b << endl;
return 0;
}
// This code will not work as there is no change in values of Actual arguments
*/
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
void swap1(int &x, int &y)
{
int temp = x;
x = y;
y = temp;
}
int main()
{
int a = 4, b = 5;
cout << "Value of a is " << a << " and value of b is " << b << endl;
// swap(&a, &b); // This will swap using pointer reference
swap(a, b); // This will swap using reference variable
cout << "Value of a is " << a << " and value of b is " << b << endl;
return 0;
}