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

How can I implement sets or arrays of bits?

595


Explain how do you print only part of a string?

642


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

598


what is stack , heap ,code segment,and data segment

2208


How to explain the final year project as a fresher please answer with sample project

459






Can you pass an entire structure to functions?

686


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

742


Is fortran faster than c?

570


Explain how can I convert a string to a number?

634


What does the && operator do in a program code?

686


Explain what is wrong with this statement? Myname = ?robin?;

986


Can a local variable be volatile in c?

571


What is variable and explain rules to declare variable in c?

545


What is register variable in c language?

590


What are the loops in c?

587