C++ Language/Indirection
Instead of directly referring to a piece of computer memory by the name of some variable, C++ software sometimes refers to it in a more indirect way.
A "pointer" is a variable whose value is a memory address.
If iVar
has already been defined as a int
variable, defining int* piVar = &iVar;
will use the "address-of" operator (&
) to obtain the address where iVar
has been stored in memory — that memory address will get stored in pointer variable piVar
.
On the other hand, a "reference" (int& riVar = iVar;
) doesn't create any additional storage; instead, it specifies a new name (riVar
) which now also refers to that same storage location that already existed for iVar
.