Pointers and References
This chapter is all about indirectly accessing values. This is achieved by having variables that store a location of another value in memory. Prior to using indirect access, you always had to access a value directly via the variable where the value in stored. Using indirect access, it is now possible to also access these values from other variables.
Indirect access makes it possible to set up relationships between entities in your programs, and to use parameters to update passed in values.
Here is an illustration of how this works:
Indirect access in C++ is achieved using references or pointers. A pointer is very flexible, and allows you to change what it points to as well as allowing you to use the pointer to access the value it refers to. This makes pointers very powerful, but also very dangerous. References are safer, but less flexible.
Example
The following demonstrates accessing a string value directly via its variable, and indirectly via a reference and also via a pointer.
Running this will output: