C:动态内存分配
如果不对malloc进行强行转换,malloc函数返回的是void类型
如果需要使用malloc函数,必须包含头文件#include <stdlib.h>
int * a;
scanf("%d",&number);
a = (int *)malloc(number * sizeof(int));
释放内存(传入指针)
free(a);
小程序:计算主机申请内存
int main()
{
void * p;
int cnt = 0;
while( p = malloc(1024*1024*100)) //1024表示1KB 1024*1024表示1M
{
cnt++;
}
printf("系统申请的空间为%d00M",cnt);
}
posted on 2019-05-13 14:59 zhaoy_shine 阅读(80) 评论(0) 编辑 收藏 举报