---
title: calloc
description: "连续内存块分配并且初始化内存为0。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0021.html
sourcePath: /source/zh/kunpengboostkithistory/2300/accel/kunpengaccel_ksl_16_0021.html
indexId: 610f2b69972bdeb9a50cdefcf3fceec3359bfd8d9e5c270ccabe109a8cd318a674
---
# calloc

连续内存块分配并且初始化内存为0。

void *calloc(size_t number_of_objects, size_t size_of_object);

#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| number\_of\_objects | 申请内存块的数量。 | 非负数 | 输入 |
| size\_of\_object | 申请内存块的字节数。 | 非负数 | 输入 |


#### 返回值

- 成功：返回指向分配内存的指针。
- 失败：返回空指针。


#### 示例

```
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "kqmalloc.h"
#define KQMALLOC_TEST_LEN 10
void CallocExample()
{
int8_t *res = (int8_t *)calloc(KQMALLOC_TEST_LEN, KQMALLOC_TEST_LEN);
if (res == NULL) {
printf("res is null\n");
} else {
printf("calloc pointer address: %lx\n", res);
free(res);
}
}
int main(void) {
CallocExample();
return 0;
}
```

运行结果：

```
calloc pointer address: ffffafe4c690
```
