forked from SE-OOP/Assignment_01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex06_50.cpp
38 lines (35 loc) · 806 Bytes
/
Ex06_50.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
#include <iostream>
using namespace std;
int tripleByValue(int a,int b) //按值传递
{
b=3*a;
a=b;
return a;
}
int tripleByReference(int & a,int & b) //引用参数传递
{
b=3*a;
a=b;
return a;
}
int main()
{
int c,b=0;
int & ok = c;
cout << "Enter a value for count:";
cin >> c ;
cout<<"\n\n";
cout << "Value of count before call to tripleByValue() is:";
cout << c << "\n";
cout << "Value returned from tripleByValue() is:";
cout << tripleByValue(c,b) << "\n";
cout << "Value of count (in main) after tripleCallByValue() is:";
cout << c << "\n";
cout <<"\n";
cout << "Value of count before call to tripleByReference() is:";
cout << c << "\n";
cout << "Value of count (in main) after call to tripleByReference() is:";
tripleByReference(ok,b);
cout << c ;
return 0;
}