Double inderection question

Doug Gwyn gwyn at smoke.ARPA
Wed Aug 3 14:40:59 AEST 1988


In article <2001 at tulum.cs.swarthmore.edu> pomeranz at cs.swarthmore.edu (Hal Pomeranz) writes:
>char array[10], **ptr;
>   ptr = &array;
>From my limited understanding 'array' is a pointer to the first element
>(i.e. a pointer to array[0]), so &array should be a pointer to the pointer.

NO.  "array" is the name of the array.  In MOST expression contexts (but
not all) it is converted to a pointer to the first member of the array
before it is used.

"&array" should give you a pointer to the array (not to its first element),
but many older compilers treat it the same as an unadorned "array".

>char array[10], **ptr, *bogus_ptr;
>   bogus_ptr = array;
>   ptr = &bogus_ptr;

"bogus_ptr" IS a pointer to char; in the context of the first assignment,
"array" is converted to a pointer to array[0] before being copied into
"bogus_ptr".  "ptr" is a pointer to "bogus_ptr" and only has anything to
do with "array" by virtue of the fact that you made "bogus_ptr" have
something to do with "array".



More information about the Comp.lang.c mailing list