In C++, the operator '&' can be overloaded. This means that the same operator can have different meanings in different contexts. There are many operators in C++ that can be overloaded.
The '&' operator usually has 3 meanings:
In the reference case:
int val1 = 2;
int &rval = val1;
In the above case
rval
Is made a reference to
val1
This means that any use of
rval
Is actually the use of
val1
Note: A reference is NOT an object. This means that a reference does NOT occupy any space in memory and, a plain reference can ONLY be bound to a non-const object. But not to a const object, a literal or the result of an expression.
Now in the pointer case :
int val1 = 2;
int *ptr = &val1;
In this case the address of 'val1' is stored in 'ptr'. But a pointer is an object which means that when we use the dereference operator '*' we're using the pointed to value. But when we don't we're using the pointer.
*ptr = 55 // pointed to value is changed
ptr = p; // the pointer's own memory
*And last but not the least, used as a bitwise operator:
A bitwise operator works with the binary digits(i.e, 0s and 1s). When we use the '&', this means that we're using the bitwise 'and' operator. This is a binary operator which means that it works with two operands. Here 'bitwise and' operator tests whether both the bits contain the binary digit '1', if so then the result is 1 else it is 0.
*not to be confused with the 'logical and' operator which contains two '&&'.