calloc : calloc « stdlib.h « C Tutorial






ItemValue
Header filestdlib.h
Declarationvoid *calloc(size_t num, size_t size);
Functionallocates sufficient memory for an array of num objects of size size.
Returnreturns 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.

All bits in the allocated memory are initially set to zero.

It is important to verify that the return value is not null before attempting to use it.

Return a pointer to a dynamically allocated array of 100 floats:

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

  int main(void){
 
    float *p;

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








23.9.calloc
23.9.1.calloc