dynamic allocation
IF
---------------------------------------- ------------
char str[] = "hello";
char str2[] = "goodbye";
char *ptr = new char[strlen(str) + 1);
strcp(ptr, str);
---------------------------------------- ------------
THEN
if i want to copy str2 into ptr, i would need to again allocate memory to ptr, enough to fit "goodbye" in it.
but the question is this. do i need to delete[] ptr; first, before executing char *ptr = new char[strlen(str2) + 1);?
----------------------------------------
char str[] = "hello";
char str2[] = "goodbye";
char *ptr = new char[strlen(str) + 1);
strcp(ptr, str);
----------------------------------------
THEN
if i want to copy str2 into ptr, i would need to again allocate memory to ptr, enough to fit "goodbye" in it.
but the question is this. do i need to delete[] ptr; first, before executing char *ptr = new char[strlen(str2) + 1);?
