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.
我们将举一