#include “pch.h”
#include < iostream >
#include < string >
#include < cstring >
#pragma warning(disable:4996)
using namespace std;
char * getname(void);
char * getname()
{
char temp[80];
cout << “Enter last name:”;
cin >> temp;
char * pn = new char[strlen(temp) + 1];
strcpy(pn, temp);
return pn;
}
int main()
{
char * name;
name = getname();
cout << name << " at " << (int *)name << endl;
delete[] name;
name = getname();
cout << name << " at " << (int *)name << endl;
delete[] name;
return 0;
}
输出结果:
Enter last name:Fredeldumpkin
Fredeldumpkin at 00115F48
Enter last name:Pook
Pook at 0011F718