forked from SE-OOP/Assignment_01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex06.50.cpp
34 lines (30 loc) · 879 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
#include <iostream>
using namespace std;
int tripleByValue(int);//function prototype
void tripleByReference(int &);//function prototype
int main()
{
int a,b;//定义参数
//对tripleByValue函数
cout <<"Enter a value for count:";
cin >> a;
cin >> b;
cout <<"Value of count before call to tripleByValue() is:"<<a<<endl;
cout <<"Value returned from tripleByValue() is:"<<tripleByValue(a)<<endl;
//cout <<"Value of count (in main) after tripleCallByValue() is:"<<count<<endl;
//对tripleByReferences参数
cout <<"Value of count before call to tripleByReference() is:"<<b<<endl;
tripleByReference(b);
cout <<"Value of count (in main) after call to tripleByReference() is:"<<b<<endl;
return 0;
}
//按值传递
int tripleByValue(int a)
{
return a=a*a*a;
}
//按引用传递
void tripleByReference(int &b)
{
b=b*b*b;
}