//In C++ reference parameters would function as so
#include <iostream>
using namespace std;
void changeVariable(int &, int &);
int main()
{
int myFirstVariable = 0;
int mySecondVariable = 13;
cout << "Before using changeVariable, myFirstVariable is: " << myFirstVariable << " and mySecondVariable is: " << mySecondVariable << endl;
changeVariable(myFirstVariable, mySecondVariable)
cout << "After using changeVariable, myFirstVariable is: " << myFirstVariable << " and mySecondVariable is: " << mySecondVariable <<endl;
return 0;
}
void changeVariable(int & varOne, int & varTwo)
{
varOne *= 2;
varTwo = varOne + 13;
}
Basically, reference parameters are very useful for changing more than one variable in one function, or even just referencing a variable instead of having to declare it every time it's changed. Any ideas?
When you pass an object or list to a function it's not making a new copy of it, so any changes you make are being made to the instance in the parent proc: