codescracker


c

C calloc()



« Previous Function Next Function »

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 :

#include<stdlib.h>
void *calloc(size_t num, size_t size);

calloc() Example

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

#include<stdlib.h>
#include<stdio.h>

float *get_name(void)
{
	float *p;
	p = calloc(100, sizeof(float));
	if(!p)
	{
		printf("Allocation Error\n");
		exit(1);
	}
	return p;
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test