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
Is it possible for a member function to use delete this?
what is Loop function? What are different types of Loops?
Can you please explain the difference between using macro and inline functions?
What do you mean by inheritance in c++?
What is c++ code?
Can a list of string be stored within a two dimensional array?
When are exception objects created?
Explain deep copy?
What apps are written in c++?
What is the difference between public, private, and protected access?
What are proxy objects in c++?
What is a c++ class?
What is the this pointer?
Which bitwise operator is used to check whether a particular bit is on or off?
Name the operators that cannot be overloaded in C++?