其他人已经解释了为什么这不起作用,即因为 a char数组和一个char指针是非常不同的东西, 不多共同。我猜你的困惑来自 这个事实,在某些条件下,数组的名称被处理为 ,好像它是一个指针(第一个元素) ) 数组,例如在 char p [] =" hello word" ;; char * pp = p; 但这只发生在数组用于值上下文时,即,即如果它被用作具有值的话。然后,只有这样,它才会意味着(通常称为它衰变成)地址 数组的第一个元素。 但是在 extern char * p; ''p''没用过在价值背景中(编译器甚至不知道 在其他地方定义了一个名为''p'的字符数组,因为 '在不同的源文件中),所以腐烂到指针,规则 不参与。 问候,Jens - \ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de \ __________________________ http://www.toerring.deOther people already explained why this won''t work, i.e. becausea char array and a char pointer are very different things, havingnot much in common. I guess your confusion is coming from thefact that under certain conditions the name of an array is dealtwith as if it would be a pointer to (the first element of) thearray, e.g. inchar 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, itis taken to mean (often called "it decays into") the address ofthe first element of the array.But inextern char *p;''p'' isn''t used in "value context" (the compiler even doesn''t knowthat somewhere else an array of chars named ''p'' was defined sincethat''s in a different source file), so the "decay to pointer" ruledoesn''t get involved.Regards, Jens--\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de\__________________________ http://www.toerring.de 这篇关于指针声明/数组定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 21:29
查看更多