首页 > 其他 > 详细

函数malloc与函数free

时间:2014-10-05 15:55:48      阅读:260      评论:0      收藏:0      [点我收藏+]

代码:

#include <stdio.h>
#include <stdlib.h>

int main(void) {

	const size_t SIZE = 5;

	// 函数malloc的返回值类型是void*
	// 函数原型:void* malloc(size_t)
	int* p = malloc(SIZE * sizeof(int));

	// int* p = (int*)malloc(SIZE * sizeof(int));

	// 如果发生错误则返回空指针
	// p == NULL 等价于 !p
	if (p == NULL) {
		exit(EXIT_FAILURE);
	}

	// 函数free释放存储空间
	// 函数原型:void free(void*)
	free(p);

	return EXIT_SUCCESS;
}


函数malloc与函数free

原文:http://my.oschina.net/Xwoder/blog/324405

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!