S
S
sddvxd2018-12-02 20:03:08
C++ / C#
sddvxd, 2018-12-02 20:03:08

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);
}

After 1 iteration crashes Unknown error with code -1073741823

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-12-02
@sddvxd

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.

V
Vasily Melnikov, 2018-12-03
@BacCM

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 question

Ask a Question

731 491 924 answers to any question