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
If null and 0 are equivalent as null pointer constants, which should I use?
Write a program to swap two numbers without using third variable in c?
Are global variables static in c?
Define C in your own Language.
What are directives in c?
Which function in C can be used to append a string to another string?
How can you increase the size of a dynamically allocated array?
main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is static and auto variables in c?
Suggesting that there can be 62 seconds in a minute?
Why enum is used in c?
How can I prevent another program from modifying part of a file that I am modifying?
What do you understand by normalization of pointers?
Is c weakly typed?