February 2005
Beginner to intermediate
272 pages
4h 53m
English
A reference is another name for an existing object. Once a reference is initialized with an object, either the object name or the reference name may be used to refer to the object.
int a = 12;int &ra = a; // ra is another name for a--ra; // a == 11a = 10; // ra == 10int *ip = &ra; // ip points to a
References are often confused with pointers, perhaps because C++ compilers often implement references as pointers, but they are not pointers and do not behave like pointers.
Three major differences between references and pointers are that there are no null references, all references require initialization, and a reference always refers to the object with which it is initialized. In the previous example, ...
Read now
Unlock full access