Consider the following program:
#include <stdio.h>
void foo(char** string)
{
printf("%s", string[0]);
}
int main()
{
char* a = "blahblah";
foo(&a);
return 0;
}
It works fine as it is, but if I substitute
char* a = "blahblah";
with
char a[] = "blahblah";
it does not work.
I get the warning expected 'char **' but argument is of type 'char (*)[9]', and a segmentation fault.
I was under the impression that char[] and char* are the same thing, so a pointer to each of them would also be the same.
(windows with mingw, gcc 4.8.1)
Thank you
char *andchar []. Hint, they're not really the same type.&a+1 - &ainmainfor each of them.&a + 1. The point is that it moves a different number of bytes with the array than with the pointer. And in the case ofchar **, it's just a pointer to the type. A pointer to a pointer is not a pointer to an array.