arrays of pointers - NOVICE QUESTION!( Be forwarned ! )

Scott Timothy Flatman flatmas at ladder.cs.orst.edu
Sun Jun 4 08:28:24 AEST 1989


Recently someone posted a remark that these two declarations are the same:
char *array[some size - you choose];
and
char **array;
My understanding is that the first declaration is for an array of pointers to
char. The second one is confusing me. How is it interpreted?

I tried looking this up in Kernighan and Ritchie. I did not get a 
satisfactory explaination. So I tried to make up a simple example along these
lines:

ex#1:
static char *array[2] = {"Hello","World"};
printf("%s %s",*array,*(array+1));

This just prints out "Hello World". I would like to do the same thing using a
declaration such as:  char **array;
and then dynamically allocating the storage for the two strings "Hello","World".
Could anybody send me a simple example. I am trying to figure out how these 
declarations are similar.Also any other bits of code along these lines that
illustrate the idea of "arrays of pointers" would be helpful to me.

Thanks for your support!

----------------------------------------------------
Scott Flatman
INTERNET: flatmas at ladder.cs.orst.edu
UUCP: hplabs!hp-pcd!orstcs!ladder.cs.orst.edu!flatmas
---------------------------------



More information about the Comp.lang.c mailing list