Sorry if this is dumb.
What does char*& mean, in something like
void someFunc(char*& buf, ...)
I understand char*, but what does the ampersand do here?
Printable View
Sorry if this is dumb.
What does char*& mean, in something like
void someFunc(char*& buf, ...)
I understand char*, but what does the ampersand do here?
When passing an address to a function, regardless of the type of variable, the function will not work on a copy of that variable, but the actual variable itself. So when you pass a char*& to a function, you are passing it the actual char pointer, not a copy. This is useful if you want to fill an array with values, for example.
You do not need to pass a reference to pointer to fill array members...
But you need it if you want to initialize the pointer in the function with new for example before filling the array... In C in this case you pass pointer to pointer, in C++ - reference to pointer