Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ex06_50.cpp #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions 201816040317/Ex06_50.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ void tripleByReference(int & );//pass-by-reference

int main()
{
int count1,count2;
int count;

cin>>count1;
cin>>count2;
cout<<"Enter a value for count:";
cin>>count;

cout<<"count1="<<count1<<" before tripleByValue\n";
cout<<tripleByValue(count1)<<endl;
cout<<"count1="<<count1<<" after tripleByValue\n"<<endl;

cout<<"count2="<<count2<<" before ripleByReferencee\n";
tripleByReference(count2);
cout<<"count2="<<count2<<" after ripleByReference\n"<<endl;
cout<<"Value of count before call to tripleByValue() is:"<<count<<endl;
cout<<"Value returned from tripleByValue() is:"<<tripleByValue(count)<<endl;//打印调用tripleByValue()函数后的值
cout<<"Value of count (in main) after tripleCallByValue() is"<<count<<endl<<endl;//打印调用tripleByValue()函数后的形参的值

cout<<"Value of count before call to tripleByReference() is:"<<count<<endl;
cout<<"Value of count (in main) after call to tripleByReference() is:"<<count<<endl;//打印调用tripleByReference()后的count的值

return 0;
}
Expand Down
34 changes: 34 additions & 0 deletions Ex06_50.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>

using namespace std;

int tripleByValue(int);//pass-by-value
void tripleByReference(int & );//pass-by-reference

int main()
{
int count;

cout<<"Enter a value for count:";
cin>>count;


cout<<"Value of count before call to tripleByValue() is:"<<count<<endl;
cout<<"Value returned from tripleByValue() is:"<<tripleByValue(count)<<endl;//打印调用tripleByValue()函数后的值
cout<<"Value of count (in main) after tripleCallByValue() is"<<count<<endl<<endl;//打印调用tripleByValue()函数后的形参的值

cout<<"Value of count before call to tripleByReference() is:"<<count<<endl;
cout<<"Value of count (in main) after call to tripleByReference() is:"<<count<<endl;//打印调用tripleByReference()后的count的值

return 0;
}

int tripleByValue(int count)
{
return count = count*3;//caller's argument not modified
}//end function tripleByValue

void tripleByReference(int &count)
{
count =3*count;//caller's argument modified
}