what is calloc and malloc?
Answers were Sorted based on User's Feedback
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 |
Answer / jothi16
calloc means reallocate the memory.malloc used to allocate
the memory
| Is This Answer Correct ? | 6 Yes | 20 No |
What is the use of define in c?
Why doesnt the call scanf work?
Is the below things valid & where it will be stored in memory layout ? static const volatile int i; register struct { } ; static register;
Why is c still so popular?
if ENTERED FIVE DIGITS DESIGN A PROGRAM THAT WILL FIND CORRESPONDING VALUE FROM ASCII TABLE
1 What is a Data Structure?
Explain what is a stream?
How can you determine the maximum value that a numeric variable can hold?
How can you draw circles in C?
What are .h files and what should I put in them?
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
Is there a way to compare two structure variables?