"hey" , , , , .
, , , , :
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
const char *hey="hey";
char* tmp=new char[4];
strcpy(tmp,hey);
cout << tmp << endl;
delete [] tmp;
return 0;
}
Notice how I managed to remove the memory new'd using tmp. I could do this:
cout << tmp << endl;
hey = tmp;
delete [] hey;
It doesn't matter if we end up pointing to the new'd memory with heyor tmpuntil we delete it correctly to avoid memory leaks.
source
share