Jump to content

C++ Language/Indirection

From Wikibooks, open books for an open world

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.

  1. Pointers
  2. Typed NULL
  3. Arrays
  4. Reference Variables
  5. Rvalue-References
  6. Smart Pointers