Interview Question

What is calloc?

calloc allocates array storage and initializes all bits to zero.

💡 Concept ✅ Quick Revision ⚙ C

Answer

calloc allocates storage for an array of objects and initializes every bit in the allocation to zero. • Its arguments specify element count and element size. • All-bits-zero is not guaranteed to represent every type’s numeric zero or null pointer value. • It returns a null pointer when allocation fails.

💡 C Example

int *values = calloc(5, sizeof *values); if (values == NULL) { return 1; } free(values);

⚡ Quick Revision

calloc allocates array storage and initializes all bits to zero.