这是源代码
int main()
{
char str[]="dance";
char str1[]="hello";
char str2[]="abcd";
strcat(str1,str2);
printf("%s",str);
}
output- bcd
why str
更改后strcat(str1,str2);
str1
没有足够的空间来连接字符串str2
。这会调用未定义的行为。你可能会得到任何东西。要么是意料之中的结果,要么是意料之外的结果。
现在试试这个:
#include <stdio.h>
#include <string.h>
int main(void) {
char str[]="dance";
char str1[10]="hello";
char str2[]="abcd";
strcat(str1,str2);
printf("%s\n",str1);
printf("%s\n",str);
return 0;
}
输出:
helloabcd
dance
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)