-
Notifications
You must be signed in to change notification settings - Fork 0
/
swap_no.cpp
60 lines (47 loc) · 868 Bytes
/
swap_no.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
#include<iostream>
using namespace std;
//so it's pass by value so the actual parameters would'nt change in this case.
// void swap(int x, int y){
// int temp;
// temp=x;
// x=y;
// y=temp;
// }
// int main(){
// int a,b;
// a=10;
// b=20;
// cout<<"first is : "<<a<<" Second is: "<<b;
// swap(a,b);
// cout<<"\nfirst is : "<<a<<" Second is: "<<b;
// }
//call by refrence
void swap(int &x, int &y){
int temp;
temp=x;
x=y;
y=temp;
}
int main(){
int a,b;
a=10;
b=20;
cout<<"first is : "<<a<<" Second is: "<<b;
swap(a,b);
cout<<"\nfirst is : "<<a<<" Second is: "<<b;
}
//call by adress
// void swap(int *x, int *y){
// int temp;
// temp=*x;
// *x=*y;
// *y=temp;
// }
// int main(){
// int a,b;
// a=10;
// b=20;
// cout<<"first is : "<<a<<" Second is: "<<b;
// swap(&a,&b);
// cout<<"\nfirst is : "<<a<<" Second is: "<<b;
// }