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
What are the types of data types and explain?
hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm
What is nested structure?
What does != Mean in c?
What is the right way to use errno?
What is d'n in c?
pierrot's divisor program using c or c++ code
What is the meaning of typedef struct in c?
Why is python slower than c?
What is string in c language?
Explain the difference between strcpy() and memcpy() function?
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
Is this program statement valid? INT = 10.50;
What is the -> in c?
Who is the founder of c language?