C++ (Functions) Run the program to see how it executes. Edit the program to get
ID: 3778700 • Letter: C
Question
C++ (Functions)
Run the program to see how it executes.
Edit the program to get the program to produce the same values for n1 and n2 after the function doStuff has executed.
i.e parVal =n1, parRef =n2
#include <iostream>
using namespace std;
void doStuff (int& parValue, int parRef){
parValue = 100;
cout << "parValue in call to do Stuff = " << parValue << endl;
parRef = 222;
cout << "parRef in call to doStuff = " << parRef << endl;
}
//and then consider the call, which we assume is in a complete and correct program
int main() {
int n1 = 1, n2 =2;
doStuff (n1, n2);
cout << "n1 after call to doStuff = " << n1 << endl;
cout << "n2 after call to doStuff = " << n2 << endl;
return 0;
}
Explanation / Answer
#include <iostream>
using namespace std;
void doStuff (int& parValue, int &parRef){
parValue = 100;
cout << "parValue in call to do Stuff = " << parValue << endl;
parRef = 222;
cout << "parRef in call to doStuff = " << parRef << endl;
}
//and then consider the call, which we assume is in a complete and correct program
int main() {
int n1 = 1, n2 =2;
doStuff (n1, n2);
cout << "n1 after call to doStuff = " << n1 << endl;
cout << "n2 after call to doStuff = " << n2 << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.