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
Can you help me with this one? Make a program that when a user inputed a Product Name, it will display its price, and when the user inputed the quantity of the inputed product, it will show its total price. The output must be like this: Product Name: Price: Quantity: Total Price: ..this is the list of products to be inputed: Cellphone - 1500 Washing Machine - 5200 Television - 6000 Refrigirator - 8000 Oven - 2000 Computer - 11000 thanks..:D
What is a hash function c++?
What is the best way to take screenshots of a window with c++ in windows?
How many standards of c++ are there?
Write bites in Turbo c++ Header ("Include") Files.
Write about a nested class and mention its use?
Why is c++ awesome?
What is the use of register keyword with the variables?
Differentiate between the manipulator and setf( ) function?
Differentiate between a pointer and a reference with respect to c++.
What is rtti in c++?
Show the declaration for a static member variable.
Is c++ the best programming language?
Can static member variables be private?
What are the various compound assignment operators in c++?