realloc函数用法
来源:互联网 发布:淘宝怎样取消货到付款 编辑:程序博客网 时间:2024/06/05 00:51
函数原型:
void *realloc(void *ptr, size_t size);
功能:
重新分配大小为size的一块内存,返回内存地址ptr。
函数源码流程图:
使用方法:
/* realloc example: rememb-o-matic */#include <stdio.h> /* printf, scanf, puts */#include <stdlib.h> /* realloc, free, exit, NULL */int main (){ int input,n; int count = 0; int* numbers = NULL; int* more_numbers = NULL; do { printf ("Enter an integer value (0 to end): "); scanf ("%d", &input); count++; more_numbers = (int*) realloc (numbers, count * sizeof(int)); if (more_numbers!=NULL) { numbers=more_numbers; numbers[count-1]=input; } else { free (numbers); puts ("Error (re)allocating memory"); exit (1); } } while (input!=0); printf ("Numbers entered: "); for (n=0;n<count;n++) printf ("%d ",numbers[n]); free (numbers); return 0;}
参考:
http://www.cnblogs.com/ladd/archive/2012/06/30/2571420.html
http://www.cplusplus.com/reference/cstdlib/realloc/
阅读全文
0 0
- realloc函数用法
- realloc函数的用法
- realloc函数用法
- realloc 函数的用法 以及 误区
- realloc 用法
- realloc 用法
- realloc 用法 .
- realloc用法
- realloc 用法
- realloc 用法
- realloc 用法
- realloc 用法
- realloc ()函数
- realloc()函数
- realloc函数
- realloc函数:
- realloc函数
- realloc函数
- HttpClient发送HTTP请求详解
- python---函数
- 用spring的beans配置mysql数据库
- 加入Java大家族
- springMVC 上传压缩包文件、解压
- realloc函数用法
- 小白的前端学习日记HTML/CSS之---九宫格
- sql语句连接查询.
- node+ejs【封装ejs模板中直接调用js方法】
- sql语句嵌套查询.
- hrbust 1614 小z的地图 dfs
- 如何:在十六进制字符串与数值类型之间转换(C# 编程指南)
- SQL 必须记住的关键字
- 程序员的成长之路