1 2 3 4

Consider now the assignment statement

/* replace "Peter" by "Paul" */

name[2] = "Paul";

Note that the compiler has built the string constant "Paul" and the assignment causes name[2]to point to it. The space that "Peter"used is still in existence, but is now inaccessible. Later we will see how to manage this memory loss better.

See King pages 262 and 263
Consider another way of forming this matrix of names:

char name[][7] = {"George", "Mark", "Peter", "Jimmy"};

name

IMAGE imgs/lec-06.sli04.gif

This is your customary 2-D array formation. Thus in C we
have two similar but distinctly different ways of
forming multidimensional arrays. The first one above
is the more efficient in terms of storage space, but
uses pointers. Also the use of char* (string) variables
warrants use of the special system functions in
<string.h>and you will have to become familiar with
these, especially
strcpy, strcmp, andstrlen

January 21, 1999

Page 4

copyright UoA