#include <iostream>
#include <cstring>
using namespace std;
char * getname(void);
int main()
{
char * name;
name = getname();
cout << name << " at " << (int *) name << "\n";
delete [] name;
name = getname();
cout << name << " at " << (int *) name << "\n";
delete [] name;
cin.get();
cin.get();
cin.get();
return 0;
}
char * getname()
{
char temp[80];
cout << "Enter last name: ";
cin >> temp;
char * pn = new char[strlen(temp) + 1];
strcpy(pn, temp);
return pn;
}
【C++学习笔记】一个使用new和delete的实例
最新推荐文章于 2021-03-16 21:07:32 发布