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 are the decision making statements in C++? Explain if statement with an example?
What is the use of ::(scope resolution operator)?
Can I run c program in turbo c++?
Define vptr.
What is #include iomanip?
Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?
What are signs of manipulation?
Can you explicitly call a destructor on a local variable?
Is c++ fully object oriented?
What is a forward referencing and when should it be used?
How is data hiding achieved in c++?
find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.
write a function signature with various number of parameters.
can any one help to find a specific string between html tags
which is changed to a sting..
weather.html looks (for location) is
Is c++ a good beginners programming language?