I am reading a post on Stack Overflow and I saw this function:
advance_buf( const char*& buf, const char* removed_chars, int size );
What does char*& buf mean here and why do people use it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It means
bufis a reference to a pointer, so its value can be changed (as well as the value of the area it’s pointing to).I’m rather stale in C, but AFAIK there are no references in C and this code is C++ (note the question was originally tagged c).
For example:
Edit: In the comments @brett asked if you can assign
NULLtobuffand if so where is the advantage of using a reference over a pointer. I’m putting the answer here for better visibility