in C++ "&" has multiple meanings.

If it is used on an existing variable it will return its adress that can be assigned to a pointer. This is useful because by using a pointer you are able to refence a variable outside of the current scope and have side effect on it. Here is an example:
   void f (string* s){
      *s="new string";
   }
   int main(){
     string s = "old string";
     cout<<s<<endl;
     f(&s);
     cout<<s<<endl;
     return 0;
   }
The output will be:
   old string
   new string
This is the same as in C but as we can see is verbose as I need to always dereference the pointer to access the variable.

C++ introduced references that can be used to ease this transferring of variables between scopes. Here is an example of it in action:
   void f(string& s){
     s="new string";
   }
   int main(){
    string s = "old string";
    cout<<s<<endl;
    f(s)
    cout<<s<<endl;
   }
The output will be the same as the code above, but we didn't need to pass the adress and then dereference it.

These methods can also be used to optimize your code: by using pointers or references the program doesn't have to copy the variable onto the stack for the function to access it, it only has to save its address.
C++ 11 has also introduced rvalue references, that can be used to further optimize your code!

Hope this explained it!
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence