函数名: malloc
功 能: 内存分配函数
用 法: #include <alloc.h>
void *malloc(unsigned size);
程序例:
#include <stdio.h>
#include <string.h>
#include <alloc.h>
#include <process.h>
int main(void)
{
char *str;
/* allocate memory for string */
/* This will generate an error when compiling */
/* with C++, use the new operator instead. */
if ((str = malloc(10)) == NULL)
{
printf("Not enough memory to allocate buffer\n");
exit(1); /* terminate program if out of memory */
}
/* copy "Hello" into string */
strcpy(str, "Hello");
/* display string */
printf("String is %s\n", str);
/* free memory */
free(str);
return 0;
}