69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#include <malloc.h>
char *getmemory(int);
int main()
{
int num=10;
char *ptr=NULL;
ptr=getmemory(num);
strcpy(ptr,"hello");
printf("%s\n",ptr);
free(ptr);
return 0;
}
char *getmemory(int num)
{
char *temp=NULL;
temp=(char *)malloc(sizeof(char)*num);//在这里申请的堆空间是由free 来释放吧,可是在这个局部函数结束的时候不会释放申请空间吗?
return temp;
}