What Does Address-of Operator Mean?
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.
Techopedia Explains Address-of Operator
Address operators commonly serve two purposes:
- To conduct parameter passing by reference, such as by name
- To establish pointer values. Address-of operators point to the location in the memory because the value of the pointer is the memory address/location where the data item resides in memory.
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.