分配和释放内存-简单

源程序:

#include <stdio.h>
#include <string.h>
#include <malloc.h>

char *GetMemory(int num)
{
char *p=(char *)malloc(sizeof(char)*num);
return p;
}

void main()
{
char *str=NULL;
str=GetMemory(100);
strcpy(str,"hello");
printf("%s ",str);
free(str);
}

原文地址:https://www.cnblogs.com/duanqibo/p/14140916.html