As promised here is my next question about pointers as strings. This question relates to how to properly free memory when deleting a pointer or exiting a program.
Will this work? No memory leaks, other problems etc...?Code:char* string = new char[8]; strcpy(string, "letters"); delete string;
Will this work? Will this delete both string and astring? Could I just set astring equal to the return of function without allocating memory first?Code:char* function (void) { char* string = new char[8]; strcpy(string, "letters"); return string; } char* astring = new char[8]; astring = function(); delete astring;
One more question, what does setting a pointer equal to NULL do? I know that NULL is just a #define 0, but does it just clear the address that the pointer points to? Or is there more? Thanks again for the help