Pointer confusion -- forgot original title

Joseph S. D. Yao jsdy at hadron.UUCP
Wed Mar 13 11:46:29 AEST 1985


> It has been my understanding, that in USE "*ptr[]" and "**ptr" are
> essentially the same and can be used interchangably.
> However, at initialization you have to declare the size of the array
> as David says above.	The reason that you can get away with
> "char *argv[]", is because the number of arguments that is passed
> to the program environment is know.(in argc)	Am I wrong?

This subject has been thouroughly thrashed to death.  If this gets back
to you and you haven't seen an incredibly long article on the subject,
send mail and I will re-post it.  Basically, yes, you are wrong.  An
array of X's declares multiple contiguous units of storage for objects
of type X.  A pointer to X declares one pointer-unit of storage in a
form that can point to an object of type X.  There are a number of
reasons that this distinction is important, primarily that a pointer
is an lvalue and must be initialised (passing an argument counts), while
an array can never be an lvalue.  The only place that the two are really
identical is as an argument to a function.  This is because, for
historical reasons (see previous article), a declaration of an array
argument to a function is IMPOSSIBLE, so when you declare an array, C
says, "oh, he really meant a pointer."   Your argument  w i l l  always
be a pointer -- an array never really gets passed.



More information about the Comp.lang.c mailing list