69,371
社区成员
发帖
与我相关
我的任务
分享
void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);//c中分配了内存,没有free()是不可能自动被释放掉的
}
void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str, "hello");
printf(str);
}
void Test(void)
{
char *str = NULL;
GetMemory2(&str, 100);
strcpy(str, "hello");
printf(str);
free(str);//在这里加个free
}
void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
中,参数char **p,指针的指针,传入&p,能够修改p的指向,