C标准库之内存操作函数——malloc
本帖最后由 漩涡鸣人 于 2014-9-13 19:05 编辑功能:malloc函数在内存中取得一块内存空间
函数原型:void * malloc(size_t size);
参数:
参数说明
size内存块的字节数
返回值:内存空间块首地址
要求:
函数需要的头文件
malloc<malloc.h>或<stdlib.h>
举例:#include <stdio.h>
#include <malloc.h>
int main(void)
{
int * buf;
buf = (int *)malloc(20 * sizeof(int));//获得一块整型数组空间
free(buf);//释放数组空间
return 0;
}
运行效果:
Good!
页:
[1]