博客
关于我
为什么存在动态内存分配,动态内存函数(malloc函数,free函数,calloc函数,realloc函数)
阅读量:111 次
发布时间:2019-02-26

本文共 1396 字,大约阅读时间需要 4 分钟。

??????

1. ??????

???????????????????????????????????????????????

  • ????????
  • ????????

?????????????????????????????

2. ?????????

?????????????

  • ??????????????????
  • ?????????????????

????????????

  • ??????????????????????

3. ????????

3.1 malloc??
  • ?????????????????
  • ???????????
  • ????????????????NULL
  • ???????
3.2 free??
  • ???????????
  • ????p????????????
  • ??p?NULL??????
  • ??????????????
3.3 ??????
??1???10?????????
#include 
#include
int main() { int *p = (int *)malloc(10 * sizeof(int)); if (p == NULL) { printf("??????\n"); } else { for (int i = 0; i < 10; i++) { p[i] = i; } for (int i = 0; i < 10; i++) { printf("%d ", p[i]); } free(p); p = NULL; } return 0;}
??2?????????
#include 
#include
int main() { int *p = (int *)malloc(INT_MAX); if (p == NULL) { printf("??????\n"); printf("????%s\n", strerror(errno)); } else { for (int i = 0; i < 10; i++) { p[i] = i; } for (int i = 0; i < 10; i++) { printf("%d ", p[i]); } free(p); p = NULL; } return 0;}
3.4 calloc??
  • ?num????size?????????????0
  • ?????????
  • ?malloc????????????0
3.5 realloc??
  • ???????????
  • ??????NULL
  • ????????
  • ????????????
  • ???????????????????

4. ??????

  • ??????????????????
  • ????????????????
  • ????????????????
  • ??realloc???????????????

转载地址:http://kpdz.baihongyu.com/

你可能感兴趣的文章
rabbitmq重启
查看>>
php实现上传(多个)文件函数封装
查看>>
php实现下载文件方法
查看>>
php实现单链表
查看>>
php实现图片背景换色功能
查看>>
php实现多个一维数组对应合并成二维数组
查看>>
php实现多关键字查找方法
查看>>
PHP实现微信公众号H5支付
查看>>
PHP实现微信公众号网页授权
查看>>
PHP实现微信小程序推送消息至公众号
查看>>
rabbitmq逻辑与开发
查看>>
php实现根据身份证获取年龄
查看>>
PHP实现的MongoDB数据增删改查
查看>>
PHP实现的SSO单点登录系统,拿走就用吧
查看>>
php实现短信验证功能
查看>>
RabbitMQ连接报错(1)—— None of the specified endpoints were reachable
查看>>
php实现逆转数组
查看>>
PHP实现通过geoip获取IP地理信息
查看>>
PHP实现页面静态化、纯静态化及伪静态化
查看>>
php容许ajax跨域,PHP设置允许ajax跨域请求的两种常见方法
查看>>