Re: More on pointers to pointers.
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 03:04:01 +0000
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)
.
- References:
- More on pointers to pointers.
- From: Chad
- More on pointers to pointers.
- Prev by Date: More on pointers to pointers.
- Next by Date: Re: More on pointers to pointers.
- Previous by thread: More on pointers to pointers.
- Next by thread: Re: More on pointers to pointers.
- Index(es):
Relevant Pages
|