void GetMem(char* pData){pData = new char[100];}char* pDDD = NULL;GetMem(pDDD);strcpy(pDDD,"hello");运行结果是什么

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/09 05:33:59
void GetMem(char* pData){pData = new char[100];}char* pDDD = NULL;GetMem(pDDD);strcpy(pDDD,

void GetMem(char* pData){pData = new char[100];}char* pDDD = NULL;GetMem(pDDD);strcpy(pDDD,"hello");运行结果是什么
void GetMem(char* pData)
{
pData = new char[100];
}
char* pDDD = NULL;
GetMem(pDDD);
strcpy(pDDD,"hello");
运行结果是什么

void GetMem(char* pData){pData = new char[100];}char* pDDD = NULL;GetMem(pDDD);strcpy(pDDD,"hello");运行结果是什么
传入的是值参,
在函数里的修改没有用.
所以pDDD在函数运行完之后还是 NULL
strcpy 这一句会出错.Runtime error.
而函数里new 的那块内存无法释放,会造成内存泄露.
void GetMem(char** ppData)
{
*ppData = new char[100];
}
char* pDDD = NULL;
GetMem(&pDDD);
strcpy(pDDD,"hello");
...
delete []pDDD;
这样还差不多.