Paul is right. If you use the address of operator you are passing a pointer which is by value to the function.
You pass by reference doing the following.
If you were passing a pointer by reference like the below, the address that the pointer points at could be modified.Code:void Function1(int & x) { // notice the & after the type of variable before the name of the variable x += 100; }
Which is essentially doing the same thing as a pointer to a pointer, just the address cannot change.Code:void Function2(int *& pX) { pX += 100; // dangerous, adds 100 integer widths to the pointer variable, not the integer it points at. }
Code:void Function3(int ** pX) { *pX += 100; // we dereference the pointer to a pointer to get a reference to the pointer, this is just the same as the above code. }




Reply With Quote