Forums Programming Assignment Help What is the difference between "calloc(…)" and "malloc(…)"?

This topic contains 1 reply, has 2 voices, and was last updated by  juwanine 5 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15178

    ahprofessional
    Participant

    What is the difference between “calloc(…)” and “malloc(…)”?

    #15184

    juwanine
    Participant

    Some important difference between calloc and malloc are given below:

    malloc:

    malloc takes only the “size” of the memory block to be allocated as input parameter.
    malloc allocates memory as a single contiguous block.
    if  a single contiguous block cannot be allocated then malloc would fail.

    calloc:

    calloc takes two parameters: the number of memory blocks and the size of each block of memory
    calloc allocates memory which may/may not be contiguous.
    all the memory blocks are initialized to 0.
    it follows from point 2 that, calloc will not fail if memory can be allocated in non-contiguous blocks when a single contiguous block cannot be allocated.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.