What is the difference between "calloc" and "malloc"?
Answers were Sorted based on User's Feedback
Answer / shweta
calloc initializes memory with 0 while malloc doesn't
initializes.
| Is This Answer Correct ? | 25 Yes | 4 No |
Answer / ven
In addiion, calloc requires two parameters whereas ,malloc
only one
| Is This Answer Correct ? | 19 Yes | 6 No |
Answer / vijay
Calloc allocates the array of blocks of memory whearas
malloc allocates the memory of the size given as an
argument.
| Is This Answer Correct ? | 12 Yes | 2 No |
Answer / saugat biswas
Malloc:
Malloc allocates memory but does not initialize it.
Example: char *szPtr = ( char* ) malloc( sizeof( char ) *
100 );
Here szPtr is assigned 100 bytes. But the memory is not
initialized. It contains garbage.
Calloc:
Allocates a block of memory for an array of 'n' elements,
each of them 'l' bytes long, and initializes all its bits
to zero.
Example: char *szPtr = ( char* ) calloc( 100, sizeof(
char ));
Here szPtr is assigned 100 bytes & the memory is
initialized to 0.
| Is This Answer Correct ? | 11 Yes | 2 No |
calloc means alloting memory dynamically
malloc means alloting memory at first and it is fixed
| Is This Answer Correct ? | 5 Yes | 3 No |
Answer / subhrajit
mallco is used in c language for static memory location in
heap area and i donot no the calloc.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / samveethsingh
malloc:
malloc create the single block of given size by user
calloc:
calloc creates multiple blocks of given size
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / edwin
malloc - create the memory space
calloc-calculate the memory space
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / srikanth
MALLOC ASSIGNS O VALUE , WHERE AS CALLOC ASSIGNS GARBAGE
VALUE.
| Is This Answer Correct ? | 3 Yes | 27 No |
what is importance of data sturture in a programming language?
22 Answers L&T, TCS, Wipro,
What is an arraylist c++?
When the design recommends static functions?
How delete [] is different from delete?
How to give an alternate name to a namespace?
what is software cycle? What is a mission critical system ? What is the important aspect of a real-time system ? Explain the difference between microkernel and macro kernel. Give an example of microkernel.Why paging is used ? Which is the best page replacement algo and Why ? What is software life cycle ? How much time is spent usually in each phases and why Which one do U want to work if selected in Honeywell ? Which are the different types of testing ? What is a distributed system ? Some questions about CSP. Which languages do U know ? What are the differences between Pascal and C. questions from Compiler construction and Lisp. Which are the different computer architecture? What is the requirement in MIMD ? What is the difference between RISC and CISC processors ? Difference between loosely coupled and tightly coupled systems ? What is an open system?
What is conversion constructor?
When do we run a shell in the unix system? How will you tell which shell you are running?
Write a corrected statement in c++ so that the statement will work properly. x + y=z;
What is helper in c++?
Does std endl flush?
What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?