What is the difference between "calloc" and "malloc"?
Answer Posted / 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 |
Post New Answer View All Answers
What is the difference between containment and delegation?
Define token in c++.
What is setbase c++?
How would perform Pattern Matching in C++?
Differentiate between an external iterator and an internal iterator?
What is a type library?
How to declare an array of pointers to integer?
How do I make turbo c++ full screen?
What is constructor in C++?
Will this c++ program execute or not?
Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL
what is pre-processor in C++?
Which coding certification is best?
How do you traverse a btree in backward in-order?
What are static and dynamic type checking?