Re: More on pointers to pointers.



Chad said:

I suspect I'm missing a broader concept here. Okay, given the following
code:

#include <stdio.h>

int main(void) {
char *ptr[] = {"Garbage", "test", "work"};
char **arg;

arg = ptr;

printf("The string is: %s\n", ptr[1]);
return 0;
}

Why am I not allowed to do something like:
arg = &ptr; ?

Because &ptr has the wrong type. ptr has the type "array of three pointers
to char", so &ptr would have the type "pointer to array of three pointers
to char", whereas arg is not of this type or a compatible type.

I guess even more to the point, why is this legal?
arg = &(*ptr) ;

& and * cancel.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages