<br>A simple variable in a program is stored in a certain number of bytes at a particular memory location, or address, in the machine. Pointers are used in programs to access memory and manipulate addresses.
<br>If v is a variable, then &v is the location, or address, in memory of its stored value. The address operator & is unary and has the same precedence and right to left associativity as the other unary operators. Addresses are a set of values that can be manipulated. Pointer variables can be declared in programs and then used to take addresses as values. The declaration
<br>declares p to be of type pointer to int. Its legal range of values always includes the special address 0 and a set of positive integers that are interpreted as machine addresses on the given C system. Some examples of assignment to the pointer p are
<br>p = (int *) 1776; /* an absolute address in memory */
<br>
<br>In the third example, we think of p as í Þreferring to ií µ or í Þpointing to ií µ or í Þcontaining the address of i.í µ In the fourth example, the cast is necessary to avoid a compiler error.
<br>The indirection or dereferencing operator * is unary and has the same precedence and right to left associativity as the other unary operators. If p is a pointer, then *p is the value of the variable of which p is the address.
<br>The name í Þindirectioní µ is taken from machine language programming. The direct value of p is a memory location, whereas *P is the indirect value of p-namely, the value at the memory location stored in p. In a certain sense * is the inverse operator to &. We want to give an explicit, yet elementary, example of how the pointer mechanism works. Let us start with the declaration
<br>We think of the pointer p as an arrow, but because it has not yet been assigned a value, we do not know what it pointers to. Suppose that our next line of code is
<br>Let us write a simple program that illustrates the distinction between a pointer value and its dereferenced value. We will use the %p format to print the value of a pointer, which on most systems produces a hexadecimal number. On ANSI C systems, the %p format is preferred. (See exercise 6, on page 312.)
<br>A pointer can be initialized in a declaration. The variable p is of type int * and its initial value is &i. Also, the declaration of i must occur before we take its address. The actual location of a variable in memory is system-dependent. The operator * dereferences p. That is, p contains an address, or location, and the expression *p has the value of what is stored at this location appropriately interpreted according to the type declaration of p.