-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut16.cpp
65 lines (53 loc) · 1.58 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
using namespace std;
void name(){
cout<<'Author: Varun Gupta'<<endl;
}
// Call by value:
// int sum(int a, int b){
// return a+b;
// }
void swap(int a ,int b)
{
int temp=a;
a=b;
b=temp;
// cout<<"After swapping: The value of a :"<<a<<"\t The values of b: "<<b<<endl;
}
// Call by using pointers.
void swapPointer(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
}
// Call by reference variables
void swapReferenceVar(int &a,int &b){ // Easy Peesy
int temp=a;
a=b;
b=temp;
}
int &swapchg(int &a,int &b) // Easy peesy.
{
int temp=a;
a=b;
b=temp;
return b;
}
int main(){
name();
// Call by value:
// cout<<"The sum of two numbers is :"<<sum(5,6)<<endl;
// Call by reference
int a,b;
cout<<"Enter the values of a and b ";
cin>>a>>b;
cout<<"Before swapping: The value of a: "<<a<<"\tThe value of b: "<<b<<endl;
//swap(a,b);
// Call by reference using pointer.
// swapPointer(&a,&b);
// Call by reference using reference variable.
swapReferenceVar(a,b);
// swapchg(a,b)=566;
cout<<"After swapping: The value of a: "<<a<<"\tThe value of b: "<<b<<endl;
return 0;
}