Referring to things - Pointers

All the expressions that we have used in our programs so far have been used to create values of the types which are either pre-defined in C or have been defined by appropriate type definitions. We have, however, sometimes needed to refer to an item not just as a value, but as a location in which a value can be stored.

The two main examples of using a reference or have been in

  1. assignment statements, where the item on the left side of the assignment has defined the location in which the value generated on the right side is to be stored;

  2. using scanf, where it is necessary to write an ampersand, &, in front of the variable into which anything but an array of characters will be read.

The destination in an assignment is an implicit reference. The compiler knows that the address of the location in memory is intended, even though only the name of the variable is written.

In the example of scanf, the programmer must explicitly write that the address (pointer) is intended by using the address operator, &. Such reference parameters are an important use of pointers, but by no means the only one.


Next - Reference parameters.

Back to Contents page.