WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?

Answer Posted / chris_sreekanth

malloc() allocates 1 unit(datatype) of memory each time it
is called so to allocate memory for a file read char by
char allocating memory each time for a char till EOF.
calloc allocates sizeof(datatype) bytes to the no of
elements in the file, where by the user can specify the
file size as the second arguement.
char *malloc(sizeof(datatype) )
char *calloc(sizeof(datatype), num of elements)
calloc() is more efficient as memory is allocated in 1
cycle so fewer clock cycles, more faster executiop.

Is This Answer Correct ?    268 Yes 63 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the red-black trees?

611


What is call by reference in functions?

573


What are the differences between new and malloc in C?

612


Can a pointer be volatile in c?

539


Why c is called a middle level language?

636






What is difference between arrays and pointers?

584


What is a program flowchart and how does it help in writing a program?

669


What is structure in c definition?

577


Explain what is wrong with this program statement?

624


What is void main ()?

617


What is dynamic dispatch in c++?

563


What is action and transformation in spark?

600


Why are algorithms important in c program?

625


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

637


Who is the founder of c language?

688