Calloc Function : Dynamic memory allocation

February 22, 2010 3 Comments » Hits : 257





Calloc Function : Dynamic memory allocation

ptr = (data_type *)calloc(No_of_elements ,sizeof(data_type));

Live Example
ptr = (int *) calloc(10,sizeof(int));
  • calloc :
    • Header File : stdlib.h
    • Allocate 20 bytes of memory
    • Sizeof Returns the Size of Parameter specified 
    • 10 means allocate space at run time for 10 elements 
    • (int *)  means Typecasting i.e Address of Block of memory is casted to address of Pointer
    • On Success : 20 bytes will be allocated
    • On Fail : Returns NULL
    • Memory Address is assigned to Pointer ptr 
    • Calloc is more efficient than malloc because it allocates memory in 1 clock cycle
    • Calloc takes 2 arguments
    • Allocates memory Block of n*sizeof(data_type )
    • Clears allocated memory with Zero

Incoming search terms:

  • music downloads legal

    Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your opinions. Any way I’ll be subscribing to your feed and I hope you post again soon.

  • http://ledlightsforcars.org Isreal Stapf

    Hi there, stumbled upon your web-site via a community forum I visit regularly, and had been curious if I could perhaps use your web site as a good resource in one of my own websites. All credit would definitely be given to the original website, that is : http://www.c4learn.com/2010/02/calloc-function-dynamic-memory.html . Would love to be able to, so please be sure to contact me at my e-mail in the event I can not: Starr@gmail.com . Thanks :)

    • Pritesh

      Thanks for your interest in link sharing. You are free to show any link from this website in your blog but unfortunately you are not allowed to create multiple copies of post , however you can show excerpt and “read more” link back to our site. :)