### Parameter-passing

Hi everyone, I'm new here so I'm I'm doing something wrong please let me know, but I really just need help with a practice exam problem. If someone could walk me through what this code is doing (or at the very least what the (int&) portions are doing, that would greatly help me, because I'm not sure and have looked everywhere for an answer. The practice question is to "Name and explain the parameter-passing disciplines...and give the output of the code."

 ``12345678910111213141516171819202122232425`` `````` #include using std::cout; using std::cin; using std::endl; int function1(int); int function2(int&); int main() { int a = 3, b = 4; int c = function1(a); int d = function2(b); cout << a << b << c << d; } int function1(int aa) { aa++; return aa; } int function2(int &bb) { bb++; return bb; } ``````
 ``123456789101112131415161718192021222324`` ``````#include using std::cout; using std::cin; using std::endl; int function1(int); // This function takes a copy of the data-type that is passed through it and modifies it. int function2(int&); // This function takes the original data-type and modifies it. int main() { int a = 3, b = 4; // Declare and init 2 variables of type int int c = function1(a); // the variable c is now equal to whatever value function1 returns, but it DOES NOT modify the value of variable a since it was passed as a copy. int d = function2(b); // the variable d is now equal to whatever value function2 returns. Since function2 is passed the actual variable itself (denoted by the ampersand), variable b is modified. cout << a << b << c << d; } int function1(int aa) { aa++; return aa; } int function2(int &bb) { bb++; return bb; }``````
Topic archived. No new replies allowed.