清明节期间学习记录,无愧对先人啊~~~LINUX ANSI C动态内存管理示范代码
2013-04-04 11:50
344 查看
我们重庆万州家人习俗是春节时为祖先上坟的。
今年回家时,我和小孩,老婆,爸妈去祖上除过草,挂过纸,放过鞭炮了。
希望祖上在另一个世界,一切安好。
清明节期间,努力学习,无愧对先人吧。。。
效果:
![](http://images.cnitblog.com/blog/465438/201304/04114713-ffa33de68c134e5681e3a6cd3664118f.png)
注意事项:
静态对象明名字的变量,可以直接对其进行操作,而动态对象是没有名字的变量,需要通过指针间接对它进行操作。
后来想想,其实计算机不会阻止很烂的程序很耗系统资源的运行。
最终,决定水平高低的还是算法,时间和空间复杂度。
SO,计算机不是万能的,人才是决定一切的因素。。。
今年回家时,我和小孩,老婆,爸妈去祖上除过草,挂过纸,放过鞭炮了。
希望祖上在另一个世界,一切安好。
清明节期间,努力学习,无愧对先人吧。。。
[root@localhost ccode]# cat realloc_example.c #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[], char* envp[]) { int input; int n; int *numbers1; int *numbers2; numbers1 = NULL; if((numbers2 = (int *)malloc(5 * sizeof(int))) == NULL) { printf("malloc memory unsuccessful."); numbers2 = NULL; exit(1); } for(n = 0; n < 5; n++) { *(numbers2 + n) = n; printf("numbers2's data: %d\n", *(numbers2 + n)); } printf("Enter an an integer value you want to remalloc (enter 0 to stop)\n"); scanf("%d",&input); numbers1 = (int *)realloc(numbers2, (input + 5) * sizeof(int)); if(numbers1 == NULL) { printf("Error (re)allocating memory"); exit(1); } for(n = 0; n < 5; n++) { printf("the numbers1s's data copy from numbers2: %d\n", *(numbers1 + n)); } for(n = 0; n < input; n++) { *(numbers1 + 5 +n) = n * 2; printf("numbers1's new data: %d\n",*(numbers1 + 5 + n)); } printf("\n"); free(numbers1); numbers1 = NULL; return 0; }
效果:
![](http://images.cnitblog.com/blog/465438/201304/04114713-ffa33de68c134e5681e3a6cd3664118f.png)
注意事项:
静态对象明名字的变量,可以直接对其进行操作,而动态对象是没有名字的变量,需要通过指针间接对它进行操作。
后来想想,其实计算机不会阻止很烂的程序很耗系统资源的运行。
最终,决定水平高低的还是算法,时间和空间复杂度。
SO,计算机不是万能的,人才是决定一切的因素。。。
相关文章推荐
- 记录一些比较好的代码管理及学习方式
- Scala 小程序记录(学习期间的代码片段)
- Linux学习记录--文件管理相关系统编程
- STM32:STM32学习记录1:MDK基本数据类型及代码优化
- 代码大全学习-30-构建管理(Managing Construction)
- jdbc学习代码记录_jdbc基本步骤
- webview学习记录(有比较详细的代码注释)
- 游戏开发学习记录03-用LeanCloud在Unity中部署后端服务代码实现
- centos7 系统管理systemd学习记录
- Linux常用进程管理工具的使用--我的学习记录
- Unity学习笔记 之 发射小球碰撞物体的代码记录
- Unity学习笔记 之 触发Unity UI 的 Button 事件 的代码记录
- win32学习之 --------GDI使用 代码记录
- 【java】 JAVA日常学习代码Demo快照记录1
- Linux学习记录--文件与目录管理
- 我的学习记录--Linux (CentOS) 程序安装包管理,yum
- VB程序学习代码记录20160714
- C语言学习基础代码记录
- 电影记录管理系统代码(笔记)
- Linux学习之CentOS(二十三)--Linux软件管理之源代码以及RPM软件包管理