Chinaunix首页 | 论坛 | 博客
  • 博客访问: 88297
  • 博文数量: 60
  • 博客积分: 4002
  • 博客等级: 中校
  • 技术积分: 645
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 18:11
文章分类

全部博文(60)

文章存档

2011年(60)

我的朋友

分类: C/C++

2011-03-30 21:36:57


calloc(m, n) is essentially equivalent to

p = malloc(m * n);

+
memset(p, 0, m * n);


There is no important difference between the two other than the number of arguments and the zero fill.

Malloc:

Allocates a block of size bytes of memory, returning a pointer to the beginning of the block. The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.

Calloc:

Allocate space for array in memory

Allocate a block of memory for an arrray of num element, each of them size bytes long, and initialized all its bits to zero.

The effective result is the allocation of an zero-initialized memory block of (num*size) bytes.

阅读(236) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~