33,311
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <malloc.h>
#include <string.h>
void GetMemory(char *p)
{
p=(char *)malloc(100);
}
void main()
{
char *str=NULL;
GetMemory(str);
strcpy(str,"hello world!");
printf(str);
}
#include <stdio.h>
#include <malloc.h>
#include <string.h>
char* GetMemory()
{
return (char *)malloc(100);
}
void main()
{
char *str=NULL;
str = GetMemory();
strcpy(str,"hello world!");
printf(str);
free(str);
}
#include <stdio.h>
#include <malloc.h>
#include <string.h>
char* GetMemory(char *p) //用返回值可以实现拷贝
{
p=(char *)malloc(100);
return p;
}
void main()
{
char *str=NULL;
str=GetMemory(str);
strcpy(str,"hello world!");
printf(str);
}