Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
An address-of operator is a mechanism within C++ that returns the memory address of a variable. These addresses returned by the address-of operator are known as pointers, because they "point" to the variable in memory.
The address-of operator is a unary operator represented by an ampersand (&). It is also known as an address operator.
Address operators commonly serve two purposes:
For example, if the user is trying to locate age 26 within the data, the integer variable would be named age and it would look like this: int age = 26. Then the address operator is used to determine the location, or the address, of the data using "&age".
From there, the Hex value of the address can be printed out using "cout << &age". Integer values need to be output to a long data type. Here the address location would read "cout << long (&age)".
The address-of operator can only be applied to variables with fundamental, structure, class, or union types that are declared at the file-scope level, or to subscripted array references. In these expressions, a constant expression that does not include the address-of operator can be added to or subtracted from the address-of expression.
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.