This means that buf is a pointer to a pointer, so its value can be changed (as well as the value of the area it points to).
I'm pretty obsolete in C, but AFAIK there are no references in C, and this code is C ++ (note that the question was originally tagged with c ).
For example:
void advance(char*& p, int i) { p += i; // change p *p = toupper(*p); // change *p } int main() { char arr[] = "hello world"; char* p = arr; // p -> "hello world"; advance(p, 6); // p is now "World" }
Edit: In the comments, @brett asked if you could assign NULL to buff , and if so, where is the advantage of using a link over a pointer. I put the answer here for better visibility.
You can assign a NULL buff . It's not a mistake. Everyone says that if you used char **pBuff , then pBuff can be NULL (like char** ) or *pBuff can be NULL (like char* ). When using char*& rBuff then rBuff can be NULL (of type char* ), but there is no object of type char** , which can be NULL .
Motti
source share