Thread: Calloc vs. Malloc

  1. #1
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002

    Calloc vs. Malloc

    Er. Can anyone tell me the difference between calloc(); and malloc(); To me, it looks like they do the same thing.........

  2. #2
    Registered User
    Join Date
    Aug 2001
    if my memory serves me correctly....forgive the pun..

    malloc allocates a block of memory for whatever..

    where as

    calloc allocates a block of memory and initializes memory to NULL

    if I am wrong then no doubt someone will tell me.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Yup - that is correct. The only difference is in the way memory is requested using calloc.

    void *calloc( size_t num, size_t size );

    void *malloc( size_t size );

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc, calloc from the FAQ
    By salvadoravi in forum C Programming
    Replies: 10
    Last Post: 01-21-2008, 03:29 AM
  2. Malloc & Calloc difference in terms of memory allocated
    By swapnaoe in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 12:57 AM
  3. Malloc and calloc problem!!
    By xxhimanshu in forum C Programming
    Replies: 19
    Last Post: 08-10-2005, 05:37 AM
  4. difference between calloc and malloc
    By saravanan_ts in forum C Programming
    Replies: 4
    Last Post: 07-28-2003, 06:13 AM