Know a good article or link that we're missing? Submit it!
*/
*/

CPLUSPLUS FAQ - Difference Between References and Pointers

References confuse me. How do they differ from pointers?

A reference is an alias to a variable, object. They are merely alternate identifiers for the same object. Note that a variable and its reference can be used interchangeably. Hence they are synonyms of each other...Although they contain the address of the object, however they are more like Constant Pointers which cannot be altered.

Regular pointers can be manipulated, i.e. incremented; decremented which can also be dangerous. However a reference cannot be manipulated. Hence they are safer to use because you are not accidentally changing the address of the variable.

int actualint;
int& otherint = actaulint;


The real usefulness of references is when they are used to pass values into functions. They provide a way to return values from the function.The reference lets you pass and return large data structures without the overhead of copying them. A reference is also a way to avoid pointer dereferencing syntax in your code. The & operator identifies a reference variable.

C++ FAQ Home
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings