-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallby_value_reference.cpp
More file actions
47 lines (39 loc) · 859 Bytes
/
callby_value_reference.cpp
File metadata and controls
47 lines (39 loc) · 859 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
#include <iostream>
using namespace std;
// call by address using pointers
void swap(int *a, int *b)
{
int temp=*a;
*a = *b;
*b = temp;
}
// simple call by address
int swaper( int &a, int &b){
int temp = a;
a = b;
b = temp;
}
// call by value
void num_swaper(int a , int b){
int temp = a;
a = b;
b = temp;
cout<<"The value of a is "
<<a
<<" and The value of b is "
<<b
<<endl;
}
int main()
{
int a, b;
cin >> a >> b;
cout << "The value of a is " << a << " and the value of b is " << b << endl;
// this is the call by address using pointers
// swap(&a,&b);
// this is the call by address
swaper(a,b);
// this is the call by value
// num_swaper(a,b);
cout << "The value of a is " << a << " and the value of b is " << b <<endl;
}