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
Should I learn c or c++ first?
Why is polymorphism useful?
Incase of a function declaration, what is extern means?
How many standards of c++ are there?
What is the most common mistake on c++ and oo projects?
What do you mean by stack unwinding in c++?
What is the precedence when there is a global variable and a local variable in the program with the same name?
Is c or c++ more useful?
Explain the auto storage classes in c++.
What doescout<<(0==0) print out a) 0 b) 1 c) Compiler error: Lvalue required
Where the memory to the static variables is allocated?
What is name hiding in c++?
Eplain extern keyword?
List the features of oops in c++?
What is a storage class? Mention the storage classes in c++.