Navigation(slideshow)

Chapter 5 - Pointers and Arrays

A pointer is a variable that contains the address of a variable. Pointers are much used in C, partly because they are sometimes the only way to express a computation, and partly because they usually lead to more compact and efficient code than can be obtained in other ways. Pointers and arrays are closely related; this chapter also explores this relationship and shows how to exploit it.

Pointers have been lumped with the goto statement as a marvelous way to create impossible-to-understand programs. This is certainly true when they are used carelessly, and it is easy to create pointers that point somewhere unexpected. With discipline, however, pointers can also be used to achieve clarity and simplicity. This is the aspect that we will try to illustrate.

The main change in ANSI C is to make explicit the rules about how pointers can be manipulated, in effect mandating what good programmers already practice and good compilers already enforce. In addition, the type void * (pointer to void) replaces char * as the proper type for a generic pointer.

  1. ["/5.01 Pointers and Addresses"]
  2. ["/5.02 Pointers and Function Arguments"]
  3. ["/5.03 Pointers and Arrays"]
  4. ["/5.04 Address Arithmetic"]
  5. ["/5.05 Character Pointers and Functions"]
  6. ["/5.06 Pointer Arrays; Pointers to Pointers"]
  7. ["/5.07 Multi-dimensional Arrays"]
  8. ["/5.08 Initialization of Pointer Arrays"]
  9. ["/5.09 Pointers vs. Multi-dimensional Arrays"]
  10. ["/5.10 Command-line Arguments"]
  11. ["/5.11 Pointers to Functions"]
  12. ["/5.12 Complicated Declarations"]

Navigation(children)

ch3n2k.com | Copyright (c) 2004-2020 czk.