WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?
Answer Posted / smitha
Malloc:
1. Takes only 1 argument- the size of the memory block to
be allocated.
2. Allocates memory as a single contiguous block.
3. Will fail if a single contiguous memory block of
required size is not available.
Calloc:
1. Takes two arguments - the number of memory blocks needed
and the size of each memory block.
2. It may or may not allocate a single contiguous block,
thus will not fail if a single contiguous memory block
of required size is not available.
3. Initialises the memory blocks to 0.
| Is This Answer Correct ? | 17 Yes | 3 No |
Post New Answer View All Answers
What is wild pointer in c with example?
What is the difference between ++a and a++?
What is difference between structure and union?
Write a program to print "hello world" without using a semicolon?
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
How do you redirect a standard stream?
What is the use of a ‘ ’ character?
What are Macros? What are its advantages and disadvantages?
What is the advantage of an array over individual variables?
Why is extern used in c?
How can I write functions that take a variable number of arguments?
the question is that what you have been doing all these periods (one year gap)
When should volatile modifier be used?
Explain how can you avoid including a header more than once?
What are the different types of endless loops?