References
Now, we'll learn what references are and how they differ from pointers.
We'll cover the following...
A reference is an alias for an existing variable. It can be created using the
&
operator.
Once created, the reference can be used instead of the actual variable. Altering the value of the reference is equivalent to altering the referenced variable.
Press + to interact
#include <iostream>int main() {int i = 20;int& iRef = i;std::cout << "i: " << i << std::endl;std::cout << "iRef: " << iRef << std::endl;std::cout << std::endl;iRef = 30; // Altering the referencestd::cout << "i: " << i << std::endl;std::cout << "iRef: " << iRef << std::endl;}