forked from rahulgoyal911/cPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalling.cpp
More file actions
65 lines (60 loc) · 697 Bytes
/
calling.cpp
File metadata and controls
65 lines (60 loc) · 697 Bytes
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
//call by value
using namespace std;
#include<iostream>
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
cout<<a<<b;
}
int main()
{
int a,b;
cin>>a>>b;
cout<<a<<b;
swap(a,b);
return 0;
}
//call by pointer
using namespace std;
#include<iostream>
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
cout<<*a<<*b;
}
int main() //main function starts here
{
int a,b;
cin>>a>>b;
cout<<a<<b;
swap(&a,&b);
cout<<a<<b;
return 0;
}
//call by reference
#include<iostream>
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
cout<<*a<<*b;
}
int main()
{
int a,b;
cin>>a>>b;
int &x=a;
int &y=b;
cout<<a<<b;
swap(x,y);
cout<<a<<b;
return 0;
}