A reference is another name for an existing variable. Unlike pointers, references cannot be null and cannot be reseated:
int x = 10;
int& ref = x; // ref IS x — same memory
ref = 20; // changes x!
cout << x; // 20
void printInfo(const string& name) {
cout << name; // can read, cannot modify
} // no copy of the string made!
const T& — read large objects cheaplyT& — modify caller's variableT* — nullable, arrays, or when reassignment neededWrite normalize(vector<double>& v) that divides every element by the maximum so the largest becomes 1.0. Modifies the vector in-place.
Click "Run" to execute your code.