calloc()
Published Aug 18, 2022
Contribute to Docs
The calloc()
function is used to dynamically allocate an array of memory blocks of a specified type. Each block has a default value of 0
.
Syntax
calloc(numberofblocks, size);
Both numberofblocks
and size
are of type size_t
.
Example
The following example showcases the calloc()
function:
int *ptr;// The pointer ptr holds the address of the first byte in the allocated memoryptr = (int*) calloc(5, sizeof(int));
The above statement allocates contiguous space in memory for 5 elements each with the size of the int
.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.