calloc is the array-oriented allocation function in <stdlib.h>: it reserves storage for a specified number of elements and sets every bit of the new storage to 0. section 13.1
Allocate a cleared integer array
size_t n = 44; int* values = calloc(n, sizeof *values); if (values) { /* values has allocated storage with all bits set to 0 */ free(values); } section 13.4 section 13.1
Use calloc with these constraints:
- Pass a strictly positive element count and element size. section 13.1
- Prefer it when an all-bits-zero representation is a valid initialization, basically for integer types. section 13.4
- Initialize floating-point or pointer-containing objects through assignment or a type-specific initialization function instead. section 13.4
#include <stdlib.h> void* malloc(size_t size); void free(void* ptr); void* calloc(size_t nmemb, size_t size); void* realloc(void* ptr, size_t size); void* aligned_alloc(size_t alignment, size_t size);
Shows calloc alongside malloc, free, realloc, and aligned_alloc in its standard-library interface. section 13.1

