Hi padawan here So do l have this situacion. l call a function twice that returns a c-string, and l save into the same char* pointer (* c_string). but is correct to delete that (* c_string) before assigning the return value again to foo() ?. Because if l dont part of the content remains, when l stepped in the debugger l can see it. Thanks in advance.
Code:char *foo (const char *_s) { char *str = new char[40]; strcpy(str, _s); strcat(str, " *** "); strcat(str, _s); return str; } int main(int argc, char* argv[]) { char *c_string; c_string = foo("monster"); printf("%s\n", c_string); delete []c_string; // is this correct before calling foo() again? c_string = foo("paragraph another"); printf("%s\n", c_string); delete []c_string; getch(); return 0; }