char StrDst[20] = "hello";
相当于
char StrDst[20];
strcpy(StrDst, "hello");
在栈上分配一个数组StrDst,将常量字符串"hello"的内容复制给StrDst数组
char *StrDst = "hello";
在栈上分配了一个指针S
trDst,将其指向常量字符串"hello"的首地址
相当于
char StrDst[20];
strcpy(StrDst, "hello");
在栈上分配一个数组StrDst,将常量字符串"hello"的内容复制给StrDst数组
char *StrDst = "hello";
在栈上分配了一个指针S
char * StrCat(char *StrDst,char *StrSrc);
#include<stdio.h>
int main(void)
{
char StrDst[20] = "hello ";
//char *StrDst = "hello ";
char *StrSrc = "world";
printf("StrDst is %s\n", StrDst);
printf("StrSrc is %s\n", StrSrc);
printf("StrDst is %s\n", StrCat(StrDst, StrSrc));
}
char * StrCat(char *StrDst,char *StrSrc)
{
char * address = StrDst;
while(*StrDst)
StrDst++;
while(*StrSrc)
{
*StrDst++ = *StrSrc++;
}
*StrDst = '\0';
return address;
}
trDst,将其指向常量字符串"hello"的首地址