CKTIS / C++
Address-of operator (&)
The unary & operator obtains the address of an object or function. Learn the resulting pointer type, the operator's restrictions, and the difference between taking an address, declaring a reference, and bitwise AND.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
&expressionThe built-in unary & operator obtains an address: for an lvalue expression of type T, &expression normally produces a pointer T* as a prvalue. It preserves qualifiers: the address of a const T object has type const T*. You cannot take the address of a bit-field or the literal 42.
Do not confuse &value with the reference declaration int& alias = value or binary bitwise AND a & b. The expression &alias points to the object bound to the reference, not a separate reference object. Taking an address does not extend the object's lifetime; do not use the pointer to read or write the object after its lifetime ends.
You can also take a function's address; for overloads, the context must uniquely select the function. The notation &C::member forms a pointer to member, not an ordinary object pointer, for a non-static data member that is neither a bit-field nor of reference type. A non-static data member can have reference type, but in that case &C::member is ill-formed.
A class can overload operator&, changing the meaning of &object. When you need the actual address despite overloading, use std::addressof(object) from <memory>. The referenced source is an evolving standard draft, not a frozen C++23 publication.
Examples
#include <iostream>
int main() {
int value = 7;
int& alias = value;
int* pointer = &value;
const int* readOnly = &value;
*pointer = 12;
std::cout << value << ' ' << *readOnly << '\n';
std::cout << std::boolalpha << (pointer == &alias) << '\n';
}
Result
12 12 true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.