Next: Character strings Up: Arrays and Pointers Previous: One-dimensional arrays

Arrays and pointers

In C, arrays and pointers are very closely connected. For example the name of the array is in fact a pointer to the first element of the array (and can be used as such without an index: a). In fact, given

   int a[10];

then a[i] is the same as *(a + i) and a is a constant (not a variable) of type int*.

This generalises further still, in that given a pointer (of the correct type) to any element of the array, then adding one to it produces a pointer to the next element (etc). In other words, pointer arithmetic is done for you, because C uses the appropriate increment for the pointed-to type (not just by adding one to the address).



Next: Character strings Up: Arrays and Pointers Previous: One-dimensional arrays


maspjw@
Tue Sep 27 15:29:34 BST 1994