void GetMemory(char *p, int num)
{
p = new char[100];
}
void Test()
{
char *str=NULL;
GetMemory(str,100);
str = "hellow Error";
这样会报错:原因是内存泄漏,在GetMemory()中动态申请的内存放在堆中,堆中的内存需要delete释放
char* GetMemoryint num)
{
char *p = new char[100];
return p;
}
void Test()
{
char *str=NULL;
str = GetMemory(100);
str = "hellow Error";