c语言calloc函数_C和C ++中的calloc()函数教程分配内存

c语言calloc函数

c语言calloc函数

calloc() function is used in C and C++ programming languages in order to allocate memory. calloc() function is used to allocate memory for the given variable type for the given count. After allocation initializes the allocated memory area by filling zeros.

C和C ++编程语言中使用calloc()函数来分配内存。 calloc()函数用于为给定计数的给定变量类型分配内存。 分配后,通过填充零来初始化分配的内存区域。

calloc()函数语法 (calloc() Function Syntax)

calloc() function has the following syntax where it accepts two parameters.

calloc()函数具有以下语法,其中接受两个参数。

void* calloc (size_t COUNT, size_t VAR_SIZE);
  • `void* calloc` is the function name where it will return a void pointer. The pointer will point the start of the allocated memory is. It is selected as void because the area can store different types of variables like int, char, float, etc.

    “ void * calloc”是函数名称,它将返回一个空指针。 指针将指向已分配内存的开始位置。 选择它为空是因为该区域可以存储不同类型的变量,例如int,char,float等。
  • `size_t COUNT` is used to set the number of elements to count for the given VAR_SIZE.

    size_t COUNT用于设置要计算给定VAR_SIZE的元素数量。
  • `size_t VAR_SIZE` is used to set a single element size where it is generally the given variable size. Generally `size()` function is used to get VAR_SIZE for the given data structure. For example `size(int)` will return the size of the single integer variable.

    size_t VAR_SIZE用于设置单个元素的大小,通常它是给定的变量大小。 通常,`size()`函数用于获取给定数据结构的VAR_SIZE。 例如,`size(int)`将返回单个整数变量的大小。

用calloc()分配内存 (Allocate Memory with calloc())

We will make an example where we will allocate memory for 5 integers in this example. We will set the allocated memory data by reading from the console and then print with printf() function.

我们将举一

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值