반응형
using the delete operator
1.source
#include <iostream> #include <cstring> using namespace std; char * getName(void); int main( int argc , char ** argv ) { char *name; name = getName(); cout << name << " at " << (int *)name << "\n\n"<< endl; delete [] name; name = getName(); cout << name << " at " << (int *)name << "\n\n"<< endl; delete [] name; return 0; } char * getName(void) { char temp[100]; cout << "Enter Last Name : "; cin >> temp; char * pn = new char[strlen(temp) + 1]; strcpy( pn, temp ); return pn; }
result
hacker@ubuntu:~/cpp$ g++ -o delete delete.cpp hacker@ubuntu:~/cpp$ ./delete Enter Last Name : black black at 0x17b7440 Enter Last Name : falcon falcon at 0x17b7440 hacker@ubuntu:~/cpp$
반응형
'C++ > 0x07-stl' 카테고리의 다른 글
using new with a structure (0) | 2016.07.29 |
---|---|
new (0) | 2016.07.28 |
vector 값 복사 (0) | 2016.07.12 |
erase (0) | 2016.07.12 |
find & erase (0) | 2016.07.12 |