Answer Posted / vadivel t
Hi Jhothi16,
how do u say calloc is for reallocation???..
Ans is,
Both are serving for the purpose of dynamic memory
allocation.
But malloc and calloc differs in two ways.
1.After allocating memory using malloc(), the data elements
in the memory will not be initialised. Means, it contains
garbage values.
But calloc() initialise all the data elements to 0.
2.malloc() allocates memory in terms of bytes.it accepts
only one argument, which says no of bytes to be allocated.
But calloc() allocates memory interms of blocks. it is
widely used when there is a need to allocated memory for an
array.
it accepts two arguments, 1st says, no of blocks to be
allocated and next argument says the size of the block.
ex:
calloc(10, sizeof(int))
-> it allocates 40 bytes, if the compiler allocates 4 bytes
for an int variable.
| Is This Answer Correct ? | 17 Yes | 1 No |
Post New Answer View All Answers
Why is not a pointer null after calling free?
What are the features of the c language?
What is difference between main and void main?
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
What is the hardest programming language?
How to delete a node from linked list w/o using collectons?
Write a program to generate the Fibinocci Series
What are the two types of functions in c?
What are the advantages of the functions?
What are the advantages of union?
Explain what are multibyte characters?
Tell us bitwise shift operators?
How many types of functions are there in c?
What is meant by errors and debugging?
What is the difference between declaring a variable by constant keyword and #define ing that variable?