answersLogoWhite

0

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 */

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What is library function in C programming?

printf, fgets, strlen, malloc etc


What is a sizeof function in C programming?

Sizeof is an example.


Is it True malloc function allocates a single block of storage space and sets all bytes to zero in C programming language?

The first part is true (malloc allocates a single block of storage) but the second part is not. Malloc is for allocating un-initialized memory. calloc initializes all bytes to 0.


What an example of a function?

In C-programming: int main (void) { return 0; }


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.


How does the free function work in c language?

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


What is really meant by malloc and where you will use this malloc?

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.


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 d command for squareroot in C programming?

There are no commands in C-programming, you should use function sqrt from math.h


Is combination a library function in c language of programming?

No.


Example of a programming language?

C, C++, Java, C-Sharp


How are input and output functions are accessed in C programming?

The most common way to invoke an input/output function is calling it by its name. Example with function puts:puts ("Hello world");