[OCLUG-devel] Initializing an array of pointers

Doug Jolley ddjolley at gmail.com
Thu Jun 23 20:54:52 PDT 2005


I'm always amazed by how text book authors can bridge huge gaps with
just a few words.

I'm studying C from a text book and the author gives the following example:

char *pS[3] = { NULL };

Then boldly says, "The difference, here, is that we now have an array
of three pointers to char, called pS, each of which is initialized to
NULL."

I would certainl agree if he had said:

char *pS[3] = { NULL, NULL, NULL };

In an earlier chapter he had said that in initializing arrays of
pointers if there are fewer elements on the right than there are in
the array, the remainder initialize to 0.  Although he didn't say so,
I suspect that he was talking about arrays of numeric elements.  It
would seem logical that if when initializing an array of pointers
there are fewer elements on the right than there are in the array, the
remainder would initialize to NULL.  Assuming that's the case (and I'm
not sure that it is), then why couldn't the array have been
initialized like this:

char *pS[3] = { };

IOW, if the default is NULL; then, why specify even one element.

Anyway, I thought I would toss this out here.  Thanks for any input.

     ... doug (Not digitally signed.)
-- 
(Not digitally signed.)


More information about the OCLUG-devel mailing list