Yes. The designation * states that what goes on the stack is a pointer, that is, the address of something. & says this is a link. 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 an element and passes it to the stack. If I call examR ,
examR(i);
I do not need it; now the compiler "somehow" passes the link - which practically means that it receives and passes the address i . On the code side, then
void examP(int* ip){ *ip += 1; }
I must definitely dereference a pointer. ip += 1 does something completely different.
void examR(int& i){ i += 1; }
always updates the value of i .
To think more, read the "call by reference" versus "call by value". The concept & gives a C ++ call by reference.
Charlie Martin Feb 27 '09 at 20:59 2009-02-27 20:59
source share