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
How can I implement sets or arrays of bits?
Explain how do you print only part of a string?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
what is stack , heap ,code segment,and data segment
How to explain the final year project as a fresher please answer with sample project
Can you pass an entire structure to functions?
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?
Is fortran faster than c?
Explain how can I convert a string to a number?
What does the && operator do in a program code?
Explain what is wrong with this statement? Myname = ?robin?;
Can a local variable be volatile in c?
What is variable and explain rules to declare variable in c?
What is register variable in c language?
What are the loops in c?