Printing pointers in C

“s” is not a “char*”, it’s a “char[4]”. And so, “&s” is not a “char**”, but actually “a pointer to an array of 4 characater”. Your compiler may treat “&s” as if you had written “&s[0]”, which is roughly the same thing, but is a “char*”.

When you write “char** p = &s;” you are trying to say “I want p to be set to the address of the thing which currently points to “asd”. But currently there is nothing which points to “asd”. There is just an array which holds “asd”;

char s[] = "asd";
char *p = &s[0];  // alternately you could use the shorthand char*p = s;
char **pp = &p;

Leave a Comment