> On Aug 13, 3:31 pm, "Jim Langston" <tazmas...@rocketmail.com> wrote:
> Would it be easier to understand if it was:
>
> void pointer_swap(int** rp1, int** rp2)
> {
> int* temp = *rp2;
> *rp2 = *rp1;
> *rp1 = temp;
>
> }
i tried and came to the conclusion that we are changing the original
pointers themselves to point then to some other place. we are not
changing the values pointed by pointers, we are changing the location
of where pointers are pointing...
am i right ?
if i am right, then it was easier than understanding references to
pointers.
if i am wrong, then Aye.... sorry.
> A reference makes it easier to understand what is going on, when you use a
> reference it is exactly like using the original variable (for most cases).
>
> So when rp1 is int*& rp1, rp1 is then a reference to an int pointer. When
> you use rp1, you are using the original int pointer.
>
> Changing rp1 iside the function, then, changes whatever variable was passed
> as the parameter, since a reference is an alias.
>
> Understand?
yep :)