-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut5.cpp
41 lines (31 loc) · 797 Bytes
/
tut5.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
#include <iostream>
using namespace std;
// this is using the address to change the value of the arguments
// int & -> returning returning reference
void swap(int& a, int& b){
int temp = a;
a = b;
b = temp;
// return a;
}
// this is using dereferencing by pointer address
void swapPointer(int* a, int* b){
int temp = *a;
*a = *b;
*b = temp;
}
int main()
{
int a = 10;
int b = 12;
cout << a << endl << b << endl;
// call by using reference variable
swap(a, b);
// swap(a,b) = 567; returning reference will make a value of address to 567
cout << a << endl << b << endl;
// call by using pointer reference
swapPointer(&a, &b); // sending the addresses
cout << a << endl << b << endl;
/* code */
return 0;
}