Hi!
I have written my own code for exercise 2 chapter7.
I then compare it with Soln7_02.cpp file from the downloaded code.
I then used only Soln7_02.cpp file cause my code was not correct!
I don't understand following lines:
Code:
char* s{ "Hello World!" };
a.sptr = new char[strlen(s)+1];
strcpy_s(a.sptr, strlen(s)+1, s);
As it seems there is a pointer to char s allocated with address of "Hello World!"
Then pointer of object a is allocated a memory space of 13 bytes (char)
And then there is a copy of string s which is 12 characters long to the sptr
which is 13 characters long.
Why the destination is made 13 characters long? Is it to accommodate the null terminating character?
Answer me this for now...
Thanks