Use of the '&' symbol in C++

In the code you provided in your question & symbol acts for passing argument by reference in your operator+ function. If you remove it your code still will be able to compile and will act the same way (in your case) but arguments will be passed in your operator+ function by value (will be copied).


It means pass by reference, the object that is passed can be manipluated directly. For example when you write public void TestMethod(obj value) any changes you make to value do not affect the original value(i.e a copy is made) however when you pass by reference any changes you make to value change the original value.


"&" can mean several different things, depending on the context.

The example you gave above is the C++ "reference operator":

Need help understanding reference operator(C++) in specific functions

The reference operator is specific to C++. "&" can also be used as the "address of" operator, used in both C and C++:

What are the differences between a pointer variable and a reference variable in C++?

Finally, "&" can also be the bitwise "AND" operator:

http://www.cprogramming.com/tutorial/bitwise_operators.html

Tags:

C++