Calloc() function attempts to grab contiguous segments of memory from the heap. - C Memory

C examples for Memory:calloc

Introduction

calloc() function takes two arguments:

  • the first determines the number of memory segments needed and
  • the second is the size of the data type.

Demo Code

#include <stdio.h> 
#include <stdlib.h> 
int main()/*from  ww  w  .j a v a2 s  . c  o m*/
{ 
   int *numbers; 
   numbers = (int *) calloc(10, sizeof(int)); 
   if ( numbers == NULL ) 
      return 1;  // return if calloc is not successful  
   
   return 0;
}

Related Tutorials