1 2 3 4

Character Arrays and Initialization

*An array of pointers to text strings (which is not the
same as a 2 dimensional array of characters) is often
used in C programming. Such a structure can be
initialized in the following way:
char* name[] = {"George", "Mark", "Peter", "Jimmy"};

IMAGE imgs/lec-06.sli03.gif

*

The last element of the array should be NULL, to serve as a marker. We can detect the end of the array in the following way:

#define NULL 0
int i = 0;
while (name[i] != NULL) {

printf("%d%s\n", i, name[i]); i++;
/* but what is the value of i?*/

0George
1Mark
2Peter
3Jimmy
4[TM][!]
5

}

January 21, 1999

Page 3

copyright UoA