-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp3.cpp
More file actions
46 lines (43 loc) · 1.14 KB
/
exp3.cpp
File metadata and controls
46 lines (43 loc) · 1.14 KB
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
# include <iostream>
using namespace std;
void swap_value(int a, int b){
int temp = a;
a = b;
b = temp;
cout<<"a inside function: "<<a<<endl;
cout<<"b inside function: "<<b<<endl;
}
void swap_reference(int &a, int &b){
int temp = a;
a = b;
b = temp;
cout<<"a inside function: "<<a<<endl;
cout<<"b inside function: "<<b<<endl;
}
int main(){
int x = -1;
int a, b;
cout<<"Enter a: "; cin>>a;
cout<<"Enter b: "; cin>>b;
while(x != 3){
cout<<"Enter choice (1 - value, 2 - reference): "; cin>>x;
switch(x){
case 1:
swap_value(a, b);
cout<<"a outside function: "<<a<<endl;
cout<<"b outside function: "<<b<<endl;
break;
case 2:
swap_reference(a, b);
cout<<"a outside function: "<<a<<endl;
cout<<"b outside function: "<<b<<endl;
break;
case 3:
cout<<"Program terminated"<<endl;
break;
default:
cout<<"Invalid choice, try again"<<endl;
break;
}
}
}