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 valid signatures for the Main function?
praagnovation
What are the disadvantages of external storage class?
a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above
ATM machine and railway reservation class/object diagram
What does 3 periods mean in texting?
in linking some of os executables are linking name some of them
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
What is %g in c?
Do character constants represent numerical values?
What are the 5 types of inheritance in c ++?
How do I determine whether a character is numeric, alphabetic, and so on?
What is a function in c?
Explain what are run-time errors?
What are the types of type qualifiers in c?