Answer the question
In order to leave comments, you need to log in
Why does the program run with an error?
Good evening. The function copies the string
inline void cpyp(char* destination, const char* source){
while(*destination++ = *source++);
}
int main(int argc, char *argv[])
{
char* pstr1 = "hello world!";
char* pstr2;
cpyp(pstr2, pstr1);
}
Answer the question
In order to leave comments, you need to log in
And he does the right thing by taking off. Memory for a copy of the string is not allocated, the pstr2 variable is not initialized.
If the code is in C++, then forget about char* as something related to strings.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question