Search code examples
c++reference

Is there any way to find the address of a reference?


Is there any way to find the address of a reference?

Making it more specific: The address of the variable itself and not the address of the variable it is initialized with.


Solution

  • References don't have their own addresses. Although references may be implemented as pointers, there is no need or guarantee of this.

    The C++ FAQ says it best:

    Unlike a pointer, once a reference is bound to an object, it can not be "reseated" to another object. The reference itself isn't an object (it has no identity; taking the address of a reference gives you the address of the referent; remember: the reference is its referent).

    Please also see my answer here for a comprehensive list of how references differ from pointers.

    The reference is its referent