Reference Parameters

Reference parameters allow us to pass a parameter by its reference rather than its value. Reference values are the norm in C++.

void swap(int& x, int& y) {
    const int temp = x;

    x = y;
    y = temp;
}

References

// Reasonable use for a reference
Employee & e = employeeList[id];

cout << e.getName() << endl;

// Useless reference
int x = 13;
int& y = x; // y is an aliases to x now
y = 36; // also changes x