C calloc function

calloc stands for contiguous allocation. It allocates memory for an array of elements and also initializes all the bits in the allocated memory to zero. It’s useful when you need a zero-initialized array or structure.

Syntax:


void* calloc(size_t num, size_t size);

Explanation:

num: The number of elements you want to allocate memory for.

size: The size of each element in bytes.

Returns a pointer to the allocated memory, or NULL if allocation fails.

Example:


int* arr = (int*) calloc(20, sizeof(int));  // Allocates and initializes an array of 20 integers to 0

This allocates memory for 20 integers and sets all of them to 0 automatically.