Isn't an array basically a const pointer to char?
#include <stdio.h>
#include <string.h>
void f(char* s)
{
strcpy(s,"ciao");
}
void main()
{
char str[10]="mamma";
char * const ptr="papa";
f(str); // <-- works as expected
printf("%s\n",str);
f(ptr); // <-- gives Segmentation fault
printf("%s\n",str);
}
How does strcpy recognize that I provide a pointer and not an array?
I'm aware that strcpy needs enough space in the destination array, but given that this char * strcpy ( char * destination, const char * source );
is the signature of strcpy, how can I infer that it needs an array as first argument?
Also, how can strcpy infer it got passed a constant pointer and not an array?