Different references have different memory addresses too. The main difference between a pointer and a reference is that a reference can only ever point to the object you originally assign it. Pointers can be manipulated, but references can't. References are mainly a convenience: they simplify uses of pointers where you're never going to need to change the pointer itself. For example,
Code:
void addOne(int *n) {
*n = *n + 1;
}
// ...
int myint = 3;
addOne(&myint);
... can more simply be written as:
Code:
void addOne(int &n) {
n = n + 1;
}
// ...
int myint = 3;
addOne(myint);
You see how the use of a reference rather than a pointer makes everything pretty much transparent; the only difference from passing by value is the & symbol.
Bookmarks