Why does this declaration give undefined result:
file1: extern char * p;
file2: char p[10];
Other people already explained why this won't work, i.e. because
a char array and a char pointer are very different things, having
not much in common. I guess your confusion is coming from the
fact that under certain conditions the name of an array is dealt
with as if it would be a pointer to (the first element of) the
array, e.g. in
char p[ ] = "hello word";
char *pp = p;
But this only happens when the array is used in "value context",
i.e. if it is used as if it had a value. Then, and only then, it
is taken to mean (often called "it decays into") the address of
the first element of the array.
But in
extern char *p;
'p' isn't used in "value context" (the compiler even doesn't know
that somewhere else an array of chars named 'p' was defined since
that's in a different source file), so the "decay to pointer" rule
doesn't get involved.
Regards, Jens