this is probably an essentially trivial thing, but it somewhat escapes me, thus far..
char * a3[2];
a3[0] = \"abc\";
a3[1] = \"def\";
char ** p;
Try
char *a3Ptr = a3;
printf("%p - \"%s\"\n", a3, *(++a3Ptr));
In C, a char array[] is different from char*, even if you can use a char* to reference the first location of an array of char.
aren't both "p" and "a3" pointers to pointers?
Yes but a3 is constant. You can't modify it.
a3 is a constant pointer, you can not increment it. "p" however is a generic pointer to the start of a3 which can be incremented.
You can't assign to a3
, nor can you increment it. The array name is a constant, it can't be changed.
c-faq
You cannot increment or point any char array to something else after creating. You need to modify or access using index. like a[1]
a3
is a name of an array. This about it as a constant pointer.
You cannot change it. You could use a3 + 1
instead of ++a3
.
Another problem is with the use of "%s
" for the *(++a3)
argument. Since a3 is an array of char, *a3
is a character and the appropriate format specifier should be %c
.