what is calloc and malloc?

Answer Posted / vadivel t

Hi Jhothi16,
how do u say calloc is for reallocation???..

Ans is,

Both are serving for the purpose of dynamic memory
allocation.
But malloc and calloc differs in two ways.

1.After allocating memory using malloc(), the data elements
in the memory will not be initialised. Means, it contains
garbage values.

But calloc() initialise all the data elements to 0.


2.malloc() allocates memory in terms of bytes.it accepts
only one argument, which says no of bytes to be allocated.

But calloc() allocates memory interms of blocks. it is
widely used when there is a need to allocated memory for an
array.

it accepts two arguments, 1st says, no of blocks to be
allocated and next argument says the size of the block.

ex:

calloc(10, sizeof(int))

-> it allocates 40 bytes, if the compiler allocates 4 bytes
for an int variable.

Is This Answer Correct ?    17 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are valid signatures for the Main function?

697


praagnovation

1774


What are the disadvantages of external storage class?

584


a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above

650


ATM machine and railway reservation class/object diagram

4794






What does 3 periods mean in texting?

593


in linking some of os executables are linking name some of them

1647


write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...

1481


What is %g in c?

610


Do character constants represent numerical values?

834


What are the 5 types of inheritance in c ++?

574


How do I determine whether a character is numeric, alphabetic, and so on?

618


What is a function in c?

567


Explain what are run-time errors?

603


What are the types of type qualifiers in c?

642