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
Are enumerations really portable?
What is include directive in c?
Why is c so important?
Explain 'bus error'?
Subtract Two Number Without Using Subtraction Operator
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
What are two dimensional arrays alternatively called as?
what is uses of .net
What is c programming structure?
What is scanf_s in c?
Where is volatile variable stored?
Explain the difference between getch() and getche() in c?
How many types of operators are there in c?
What do you mean by a local block?
Write a c program to build a heap method using Pointer to function and pointer to structure ?