Pointers and References

Pointers come from plain C, and references were added by C++. They have both similarities and differences which can be terribly confusing. This page is supposed to point out some of these, in the faint hope that it will make some sense.

Pointers are the more general facility. Anything you can do with a reference, you could re-write to do with a pointer. Some pointer jobs cannot be done with a reference.

If something can be written using either pointers or references, both versions will likely produce essentially the same machine code. The source code differences are artifacts of the language design and semantics.