The following code
#include <stdio.h>
char * arr[]={"my","array"};
main()
{
printf("%p %p\n",arr, &arr);
char *(*arr_ptr)[2];
arr_ptr = &arr;
arr_ptr = arr;
}
compiles with the warning
2.c: In function ‘main’: 2.c:15:10: warning: assignment from incompatible pointer type [enabled by default] arr_ptr = arr;
However, being run, the compiled program would print two identical numbers.
The conclusion is that there exists a dissimilar type, namely 'pointer to the array', that points to exactly the first element of the array.
My question is: what is the reason for such a pointer type to exist, isn't just having arr
as an pointer to the array not enough?