answersLogoWhite

0

What is different between malloc and free?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

malloc reserves memory for your use, free removes the reservation done by malloc and makes the memory available for other applications.

Note: both of them is a special case of realloc:

malloc (n) = realloc (NULL, n)

free (p) = realloc (p, 0)

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is different between malloc and free?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the different types of memory allocations in c?

1.malloc 2.calloc 3.realloc 4.free


Function used to free memory allocated by malloc?

The free() function.


Comparison of C' malloc and free functions with c new and delete operators?

Hi, The difference between new and malloc: 1.The New is a operator however malloc is a function 2.New returns the object type and there is no typecasting required. In malloc type casting should be done as it returns a void*. 3. The new operator can be overloaded however there is no over loading in C and hence Malloc can not be overloaded. 4. Operater New asks for the number of objects to be allocated however in malloc it will ask you for the number of bytes to be allocated. 5. The New operater will return you a exception of memory is not available however in malloc it will return u a NULL. 6. New is a concept for dynamically allocation in OOPS(C++) however malloc is used in C. The difference between the delete and free is as follows: 1. delete is a operator and can be overloaded however free is a function and can not be overloaded. With Regards, Shashiraja Shastry


What is the difference between allocating memory through heap and malloc?

Nothing, malloc does allocate memory from the heap.


How do you free two dimensional dynamic array?

Depends on how you allocated it: every malloc has to to have a corresponding free.


How does the free function work in c language?

free() marks the memory locations as available for malloc().


71 Which function should be used to free the memory allocated by calloc?

free() is a function used to free the memory allocated dynamically ,by both malloc and calloc functions. free(ptr): ptr is a pointer to a memory block which has already been creeated by malloc or calloc.


What is the malloc function?

The malloc function is one of a group of memory allocation functions; malloc, calloc, realloc, and free. Specifically malloc (size) returns a pointer to a new memory block of at least size bytes, suitably aligned for optimum access for any basic type, or it returns a NULL if the request cannot be satisfied.


How can we create an unsized array to c programme?

Use a pointer... int a*; a = malloc(sizeof(int)*100); //allocate space for 100 elements free(a); a = malloc(sizeof(int)*1000); // allocate space for 1000 elements free(a);


How you use malloc function in c?

void* malloc (size_t bytes); This means that malloc takes an argument which is the size of memory to allocate and returns a pointer to that memory which has been allocated. If the return value is NULL, then the request could not be satisfied. Each call to malloc must be balanced with a corresponding call to free, to release the memory. int pa = NULL; pa = (int*) malloc (sizeof(int) * 1000); /* allocate 1000 ints */ if (pa == NULL) throw exception... ... use pa free (pa); pa = NULL;


What is a malloc function in C programming with example?

The malloc() function is part of a class of functions that deal with the allocation of memory on the heap. int *a = malloc (sizeof (int) * 100); /* allocate 100 int's */ if (a == NULL) {...} /* deal with possible malloc failure */ /* use a, either as pointer or as array of 100 ints */ free (a); /* release memory back to the library */


How memory allocates for node in data structures?

I guess it's functions malloc and free, what are you thinking of.