-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut16.cpp
39 lines (35 loc) · 976 Bytes
/
tut16.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
#include<iostream>
using namespace std;
int sum (int a,int b){
int c = a+b;
return c;
}
void swap(int a, int b){
int temp =a;
a=b;
b= temp;
}
void swapPointer(int *a, int *b){
int temp =*a;
*a=*b;
*b= temp;
}
int & swapReferenceVar(int &a, int &b){
int temp =a;
a=b;
b= temp;
return a;
}
int main()
{
int a = 5, b = 8;
cout<<"The sum of two number is "<<sum(a,b)<<endl;
cout<<"The value of a is "<<a<<" and the value of b is "<<b<<endl;
swap(a,b);
// This will not swap because a and b are actual parameter so this will not effect the value of the code.
cout<<"The value of a is "<<a<<" and the value of b is "<<b<<endl;
// swapPointer(&a,&b);//This will swap a and b by call by refernce using pointer
swapReferenceVar(a,b) = 766;//This will swap a and b by call by reference using reference variable
cout<<"The value of a is "<<a<<" and the value of b is "<<b<<endl;
return 0;
}