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
What is a structure in c language. how to initialise a structure in c?
How can I recover the file name given an open stream?
How was c created?
Explain what does it mean when a pointer is used in an if statement?
Are there constructors in c?
How can I direct output to the printer?
How can a process change an environment variable in its caller?
Write a program to print "hello world" without using a semicolon?
What is the significance of scope resolution operator?
How to create struct variables?
What is .obj file in c?
Explain the red-black trees?
What is actual argument?
in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none
swap 2 numbers without using third variable?