Chapter 5: Pointers and Arrays

page 93

Pointers are often thought to be the most difficult aspect of C. It's true that many people have various problems with pointers, and that many programs founder on pointer-related bugs. Actually, though, many of the problems are not so much with the pointers per se but rather with the memory they point to, and more specifically, when there isn't any valid memory which they point to. As long as you're careful to ensure that the pointers in your programs always point to valid memory, pointers can be useful, powerful, and relatively trouble-free tools. (In these notes, we'll be emphasizing techniques for ensuring that pointers always point where they should.)

If you haven't worked with pointers before, they're bound to be a bit baffling at first. Rather than attempting a complete definition (which probably wouldn't mean anything, either) up front, I'll ask you to read along for a few pages, withholding judgment, and after we've seen a few of the things that pointers can do, we'll be in a better position to appreciate what they are.

section 5.1: Pointers and Addresses

section 5.2: Pointers and Function Arguments

section 5.3: Pointers and Arrays

section 5.4: Address Arithmetic

section 5.5: Character Pointers and Functions

section 5.6: Pointer Arrays; Pointers to Pointers

section 5.7: Multi-dimensional Arrays

section 5.8: Initialization of Pointer Arrays

section 5.9: Pointers vs. Multi-dimensional Arrays

section 5.10: Command-line Arguments


Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995, 1996 // mail feedback