C++ parameter passing is a very subtle idea but an important one.

There are three types of passing in C++:

- Value (or copy)
- Reference (or passing the address of the variable)
- Const-reference (same as above except the object can't be modified)

Passing by value means you want C++ to make a copy of the variable you send in:

void f(int x) { x = 5; }
int z = 4;
f(z);
cout << z << endl;

The value of z will be 4. This is because in f you are only working with a copied local version of z. However, if we wanted to modify the variable we could change the signature of the function like so:

void f(int & x) { x = 5; }
int z = 4;
f(z);
cout << z << endl;

z will now be 5. This is because we are telling C++ to send in the address of z rather than a copy. This is a very subtle idea because lets say you had the following:

void f(vector<LARGE_CLASS>; x) { cout << x.at(0) << endl; }
vector<LARGE_CLASS>; x;
f(x);

A copy of the vector will be sent to the function (well really the copy constructor will get called - which the end result would be a copy of the vector array).

What should be done is the following:

void f(vector<LARGE_CLASS>; & x) { cout << x.at(0) << endl; }
vector<LARGE_CLASS>; x;
f(x);

However, there may be instances in which you want to send the address but don't want to allow the function to modify the vector. You could use the const keyword for that like:

void f(const vector<LARGE_CLASS>; & x) { cout << x.at(0) << endl; }
vector<LARGE_CLASS>; x;
f(x);

By adding const the following code will not work/compile:

void f(const vector<LARGE_CLASS>; & x) { x.push_back(LARGE_CLASS()); }
vector<LARGE_CLASS>; x;
f(x);

There is a third way to pass parameters which would allow a user of your function/method to pass in a NULL/nullptr value. This notation marks it as a pointer, which is fine but you call it slightly differently:

void f(int * x) { *x = 5; }
int z = 4;
f(&z);
cout << z << endl;