Previous: 6.1 What is a Pointer?
Up: 6 Pointers
Next: 6.3 Returning to the Payroll Task with Pointers
Previous Page: 6.1.2 Indirect Access of Values
Next Page: 6.2.1 Indirectly Incrementing a Variable
As we have seen, in C, arguments are passed to functions by value; i.e. only the values of argument expressions are passed to the called function. Some programming languages allow arguments passed by reference, which allows the called function to make changes in argument objects. C allows only call by value, not call by reference; however, if a called function is to change the value of an object defined in the calling function, it can be passed a value which is a pointer to the object. The called function can then dereference the pointer to access the object indirectly. We have also seen that a C function can return a single value as the value of the function. However, by indirect access, a called function can effectively ``return'' several values. Only one value is actually returned as the value of the function, all other values may be indirectly stored in objects in the calling function. This use of pointer variables is one of the most common in C. Let us look at some simple examples that use indirect access.