answersLogoWhite

0


Best Answer

malloc is a function of the standard c library (stdlib) and it is abbreviation for memory allocate. What this function does is allocates memory in the RAM of computer to store variable data in it. You will use it whenever you need a place to store you temporary data such as an array or structure. To use malloc all you have to do is call malloc and tell it the size of the memory you want. It will then return a pointer to that memory. persumabely if it fails it returns NULL.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is really meant by malloc and where you will use this malloc?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you use 2-D array with malloc?

You use a 2-D array with malloc the same way you use any other structure or scalar with malloc. The malloc library call takes a single argument of type size_t (in bytes) and returns a void* pointer to a region of memory that is suitably aligned for any supported data type. An example using the 2-D array... int *myArray[10][20]; myArray = malloc (sizeof (myArray)); if (myArray == NULL) {...exception processing...}; Note that a 2-D array is really the same as a 1-D array - its a linear region of memory - its just that the compiler does address arithmetic for you.


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 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 different between malloc and free?

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)


How do you declare an N-Dimensional array using Malloc?

#include <stdlib.h> int **array1 = malloc(nrows * sizeof(int *)); for(i = 0; i < nrows; i++) array1[i] = malloc(ncolumns * sizeof(int));


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

Nothing, malloc does allocate memory from the heap.


What is really meant when you say an appliance use up electricity?

the current disappears!!:))


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);


Where not to use a curry comb?

Not meant to use it on mane and tail but I do and i have HOYS ponies so not really any where you can't


What if happen when you allocate memory by using malloc or calloc when the momory is not available contigiously?

malloc/calloc/realloc will return NULL


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.


What is the difference between delete and free?

Are you talking about freeing dynamically allocated memory in C/C++? free() is a function that you use to release dynamically (i.e. at run-time) created memory in C, using malloc() or alloc() or such other functions. In the same way, delete() is a function that is used in C++ to release memory created at run-time using the function new(). (Note that you can still use malloc and other C functions in your C++ code, but it is not considered a good programming habit. Moreover, new() is easier to use and more flexible, once you get the hang of it. If this is not what you had in mind, then I do not know if this will be of any help to you. addition: -new is constructor of which delete is destructor so use in pairs always.. similarly use malloc with free.. extra note: - no type cast required for new , whereas malloc, free may require it. - new returns exception whereas malloc returns NULL when memory issue.