Calloc vs. Malloc

This is a discussion on Calloc vs. Malloc within the C Programming forums, part of the General Programming Boards category; Er. Can anyone tell me the difference between calloc(); and malloc(); To me, it looks like they do the same ...

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

    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
    Posts
    247
    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
    Posts
    343
    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
    Location
    The edge of the known universe
    Posts
    32,821

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, 01:57 AM
  3. Malloc and calloc problem!!
    By xxhimanshu in forum C Programming
    Replies: 19
    Last Post: 08-10-2005, 06:37 AM
  4. difference between calloc and malloc
    By saravanan_ts in forum C Programming
    Replies: 4
    Last Post: 07-28-2003, 07:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21