WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?
Answer Posted / tinku
There are two differences.
First, is in the number of arguments.
Malloc() takes a single argument (memory required in bytes),
Calloc() needs two arguments.
Secondly, malloc() does not initialize the memory allocated, while
calloc() initializes the allocated memory to ZERO.
calloc() allocates a memory area, the length will be the product of its parameters. calloc fills the memory with ZERO's and returns a pointer to first byte. If it fails to locate enough space it returns a NULL pointer.
Syntax: ptr_var=(cast_type *)calloc(no_of_blocks , size_of_each_block);
i.e. ptr_var=(type *)calloc(n,s);
malloc() allocates a single block of memory of REQUSTED SIZE and returns a pointer to first byte. If it fails to locate requsted amount of memory it returns a null pointer.
Syntax: ptr_var=(cast_type *)malloc(Size_in_bytes);
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is an lvalue in c?
What is an array? What the different types of arrays in c?
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
What are the key features in c programming language?
What is the difference between array and linked list in c?
In a switch statement, what will happen if a break statement is omitted?
I just typed in this program, and it is acting strangely. Can you see anything wrong with it?
#include
What is string length in c?
Where we use clrscr in c?
What is the mean of function?
What is a far pointer in c?
Can a variable be both const and volatile?
Tell us bitwise shift operators?
How many levels of pointers can you have?