strcpy()接受的参数类型?

strcpy()接受的参数类型?,c,string,strcpy,C,String,Strcpy,为什么strcpy()接受字符数组指针,即使strcpy的定义是 char*strcpy(char*,const char*) #include <stdio.h> #include <string.h> main() { char str[] = "Have A Nice Day"; char ptr[17]; strcpy(ptr, str); printf("%s", ptr); } #包括 #包括 main() { char

为什么
strcpy()
接受字符数组指针,即使
strcpy
的定义是
char*strcpy(char*,const char*)

#include <stdio.h>
#include <string.h>

main()
{
    char str[] = "Have A Nice Day";
    char ptr[17];

    strcpy(ptr, str);
    printf("%s", ptr);

}
#包括
#包括
main()
{
char str[]=“祝您有愉快的一天”;
char-ptr[17];
strcpy(ptr,str);
printf(“%s”,ptr);
}

字符[n]给出了一个地址,可以用来代替常量指针,并在声明时分配内存。

在C/C++数组中也是指针。 有关更多说明,请参见此处。

数组不是指针(尽管它们在行为和用法上类似),但在需要指针的上下文中,它会透明地衰减为指针(例如,它作为参数传递给需要指针的函数)


更深入的描述可以在.

的可能副本中找到。另请参见:我猜OP询问的是
const
非数组vs指针数组不是指针。但是数组标识符可以隐式转换为指向第一个数组元素的指针。从链接文章中,“指针和数组之间的区别,我在很多地方都看到了数组被引入指针。这在技术上是不正确的。数组不是指针。那么它是什么?它就像C++中的任何其他变量。”
char[]
不是常量指针,它是不完整的数组类型。两者并不等同。尝试编译
extern char a[];char f(){返回一个[0];}
vs
extern char*const a;char f(){返回[0];}
并查看差异。