void getmemory(char *p)
{
p=(char *) malloc(100);
}
int main( )
{
char *str=NULL;
getmemory(str);
strcpy(p,"hello world");
printf("%s/n",str);
free(str);
return 0;
}
关于malloc不能返回动态内存是什么意思,
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答
threenewbee 2016-08-23 08:43关注void getmemory(char **p) { *p=(char *) malloc(100); } int main( ) { char *str = NULL; getmemory(&str); strcpy(str,"hello world"); printf("%s/n",str); free(str); return 0; }解决 无用评论 打赏 举报