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

Jon W{tte d88-jwa at nada.kth.se
Mon Jun 5 00:51:35 AEST 1989


In article <> flatmas at ladder.CS.ORST.EDU (Scott Flatman) writes:
>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?

The first and the second declarations are identical for all normal uses
as long as you leave the size of the array out i.e.
char *foo[]    ==     char **foo
The ** stands for "pointer to pointer", and since the first pointer
can be temporarily incremented using an "index", this pointer could
as well be a pointer to an array of pointers. The difference is
syntactical -- char *foo[] may be used in formal declarations/parameters
only! Also, the char *argv[] works, the char **argv doesn't, on my machine
(Speaking of main(argc, argv), that is...) This might be a bug in the
* ancient * compiler I use.

Be warned ! IF you specify a size within the brackets, the compiler
reserves memory for your array, but if you use **, you have to do
the memory allocation yourself using malloc() (Or, on certain systems,
mreserve(), NewHandle(), getmem() ...)

I hope this clarifies at least some of your questions. Flames may
be sent to /dev/null or your local fortune cookie administrator.
-- 
 __       Jon W{tte (The dread Smiley Shark) email:h+ at nada.kth.se
/  \      (+46 (0) 8 258 268)
   /---   (c) 1989 Yessbox Allright Professional Products Inc. - Y.A.P.P.I.
  /       -- No More --



More information about the Comp.lang.c mailing list