Address Operators

The C language has two operators that work with memory addresses. Table 6.7 lists C's address operators.

Table 6.7 Address Operators

Operator Operation

& Yield address of the operand
* Yield value contained at the operand's address

Both address operators are often used with pointers—variables that contain the addresses of other variables. Chapter 8, “Pointers,” and Chapter 9, “Advanced Pointers,” are devoted to explaining pointers, including the use of these two operators with them. Since you must understand pointers in order to understand these operators fully, we'll describe them briefly here and elaborate on their use in Chapter 8.

The “address-of operator” (&) yields a constant equal to the machine address of its operand. For instance, if the variable val contains the value 10, and its storage is located at address 1508, the expression val yields the value 10, while the expression &val yields the constant 1508.

Since the address-of operator yields a constant, you can't assign a value to an expression that uses it. The statement

&val = 20;

is illegal for the same reason that the statement

1508 = 20;

won't pass muster.

The “indirection operator” (*) yields the value contained in the address referenced by its operand. If you declare ptr as a pointer variable, the expression

*ptr

yields the contents of the address to which ptr points.