refrence to a pointer
given a pointer
type * ptr;
When or why would you pass the pointer by refrence to a function ie
Instead of simply passing the address directly
I saw this done and don't understand why.
The prototype for the pass by refrence example
A pointer to a pointer. I do not understand.
if the function wanted to change the pointer and not the referenced data it would need to be passed a pointer to the pointer.
Remember that, like any other variable, a pointer itself has an address in memory. When you pass a pointer to a function, a copy of it is made. This copy obviously has a different address than the original. That's why you can do:
The original pointer is unaffected.
void print(char * s)
while(*s != 0)
cout << *(s++);
cout << endl;
Now let's say you wanted to write a function in C that increments a pointer. You would have to do:
With C++, it's simply more readable (and less typing) to use:
void inc(char ** p)
void inc(char * & p)
I got it so given
ptr is the address of the data the pointer points to or in other words is refrenced by
&ptr is the address of the pointer which in turn refrences some data.