UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

Arrays of Pointers

Since variables can be pointers, it should come as no surprise that we can create arrays of pointers. We declare variables to be "pointer to int" using int *. We declare arrays using brackets ([ ] ). We can combine them to declare an "array of pointers to int" with int *pInts[5]; This declares pInts to be an array of 5 pointers to int.
that is, pInts[0] can point to some int, pInts[1] can point to another int, and so on. Pictorially, we have

One of the most common uses for arrays of pointers is an array of character pointers. Each character pointer points to a string. We can declare an array of char pointers and initialize them to essentially create an array of strings. For example

char *months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; which we can think of as looking like this:

then we can reference

months[3] to mean "April", An array of "pointers to chars" is used to pass command line arguments to your program.


CSEE | 201 | 201 F'06 | lectures | news | help

Tuesday, 22-Aug-2006 07:14:11 EDT