原型:extern void *malloc(unsigned int num_bytes);
用法:#include <alloc.h>
功能:分配长度为num_bytes字节的内存块
说明:如果分配成功则返回指向被分配内存的指针,否则返回空指针NULL。
当内存不再使用时,应使用free()函数将内存块释放。 举例:// malloc.c #include <syslib.h> #include <alloc.h> main() { char *p; clrscr(); // clear screen p=(char *)malloc(100); if(p) printf("Memory Allocated at: %x",p); else printf("Not Enough Memory!\n"); free(p); getchar(); return 0; }相关函数:calloc,free,realloc