使用strcpy源后,损坏并获得正确的目标.以下是我的代码请告诉我为什么我的源代码被破坏了?如果我将第二个字符数组q []保持固定大小,那么我的源码不会被更改.为什么这种奇怪的行为.-
我正在使用MSVC 2005
void function(char* str1,char* str2);
void main()
{
char p[]="Hello world";
char q[]="";
function(p,q);
cout<<"after function calling..."<<endl;
cout<<"string1:"<<"\t"<<p<<endl;
cout<<"string2:"<<"\t"<<q<<endl;
cin.get();
}
void function(char* str1, char* str2)
{
strcpy(str2,str1);
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
after function calling...
string1: ld
string2: Hello world
Run Code Online (Sandbox Code Playgroud)
提前
谢谢马拉蒂