include iostream using namespace std void callByValue int 10 cout Insi

 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
#include <iostream>
using namespace std;
void callByValue(int a)
{
a = 10;
cout << "Inside callByValue: " << a << endl;
}
void callByReference(int &a)
{
a = 10;
cout << "Inside callByReference: " << a << endl;
}
void callByRef(int* a)
{
*a = 10;
cout << "Inside callByRef: " << *a << endl;
}
int main()
{
cout << "Let start!\n";
int i;
i = 0;
cout << "Before callByValue: " << i << endl;
callByValue(i);
cout << "After callByValue: " << i << endl;
i = 0;
cout << "Before callByReference: " << i << endl;
callByReference(i);
cout << "After callByReference: " << i << endl;
i = 0;
cout << "Before callByRef: " << i << endl;
callByRef(&i);
cout << "After callByRef: " << i << endl;
return 0;
}