-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassByValue.cpp
More file actions
37 lines (33 loc) · 666 Bytes
/
PassByValue.cpp
File metadata and controls
37 lines (33 loc) · 666 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
#include <iostream>
using namespace std;
//g++ PassByValue.cpp && ./a.out
class emp{
public:
char name;
emp(char nameParam){
name=nameParam;
}
void setName(char nameParam){
name=nameParam;
}
char toString(){
return name;
}
};
void foo(emp a,emp b){
a.setName('1');
b= emp('2');
}
void fooRef(emp &a,emp &b){
a.setName('1');
b= emp('2');
}
int main()
{
emp a('a');
emp b('b');
foo(a,b);
cout << "after passbyVal a = " << a.toString() << " b = " << b.toString() << "\n";
fooRef(a,b);
cout << "after passByRef a = " << a.toString() << " b = " << b.toString() << "\n";
}