Yes. The *
notation says that what's being pass on the stack is a pointer, ie, address of something. The &
says it's a reference. The effect is similar but not identical:
Let's take two cases:
void examP(int* ip);
void examR(int& i);
int i;
If I call examP
, I write
examP(&i);
which takes the address of the item and passes it on the stack. If I call examR
,
examR(i);
I don't need it; now the compiler "somehow" passes a reference -- which practically means it gets and passes the address of i
. On the code side, then
void examP(int* ip){
*ip += 1;
}
I have to make sure to dereference the pointer. ip += 1
does something very different.
void examR(int& i){
i += 1;
}
always updates the value of i
.
For more to think about, read up on "call by reference" versus "call by value". The &
notion gives C++ call by reference.