Pointers and References

Steven Zeil

October 2, 2013

Course Home   e-mail

In this lesson, we examine the data types that C++ provides for storing addresses of data.

These are important because they

1 References
2 Pointers
 2.1 Working with Pointers
 2.2 Pointers Can Be Dangerous
3 The Secret World of Pointers
 3.1 Pointers and Arrays
 3.2 Pointer and Strings
 3.3 Pointers and Member Functions

Indirection   


It’s rather like answering a question about, say, the meaning of the word “Ragnarok” by pointing to a nearby dictionary instead of explaining it directly.

In our code, sometimes we will employ this indirection for efficiency. In other cases we use it for flexibility or to simplify our code.

A pointer or reference is the "name" or "address" of an object NOT the object itself.

Most variables have names assigned to them by the programmer at the time the program is written (e.g. "int numberOfCourses;"). Every variable in a program has an machine address where that variable is stored in the main memory of the computer. Think of this as the "machine’s name" for the variable.

Every variable in a program has a value which is the data stored in the variable’s address.

[Previous]