C calloc()

The calloc() function allocates memory the size of which is equal to the num * size. That is, calloc() allocates sufficient memory for an array of num objects of size size. All bits in the allocated memory are initially set to zero.

The calloc() function returns a pointer to the first byte of the allocated region. If there is not enough memory to satisfy the request, a null pointer is returned. It is always important to verify that the return value is not null before attempting to use it.

calloc() Syntax

Following is the syntax of the calloc() function :

void *calloc(size_t num, size_t size);

calloc() Example

Following function returns a pointer to a dynamically allocated array of 100 floats :


float *get_name(void)
	float *p;
	p = calloc(100, sizeof(float));
		printf("Allocation Error\n");
	return p;

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋