### Question 6.8

Practically speaking, what is the difference between arrays and pointers?

Arrays automatically allocate space, but can't be relocated or resized. Pointers must be explicitly assigned to point to allocated space (perhaps using `malloc`), but can be reassigned (i.e. pointed at different objects) at will, and have many other uses besides serving as the base of blocks of memory.

Due to the so-called equivalence of arrays and pointers (see question 6.3), arrays and pointers often seem interchangeable, and in particular a pointer to a block of memory assigned by `malloc` is frequently treated (and can be referenced using `[]`) exactly as if it were a true array. See questions 6.14 and 6.16. (Be careful with `sizeof`, though.)

See also questions 1.32 and 20.14.

Read sequentially: prev next up top

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