我写的一端代码:
mian()
{
char *p[2]={'\0'};
char *s="asdf";
strcpy(p[0] ,s);
}
可是为什么p[0]的内容依然是NULL。
但是写成这样也不对。
mian()
{
char *p[2]={"",""};
char *s="asdf";
strcpy(p[0] ,s);
}
这样的话p[0]="asdf",p[1]="sdf";
这是为什么呢??
mian()
{
char *p[2]={'\0'};
char *s="asdf";
strcpy(p[0] ,s);
}
可是为什么p[0]的内容依然是NULL。
但是写成这样也不对。
mian()
{
char *p[2]={"",""};
char *s="asdf";
strcpy(p[0] ,s);
}
这样的话p[0]="asdf",p[1]="sdf";
这是为什么呢??
strcpy(p[0] ,s); 不是让两个指针指向同一地址,而是将第二个地址的内容拷到第一个地址中去。