O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Memory Handling: malloc.h

Memory blocks are very useful in C programming, especially when creating dynamic arrays or when working in memory-restricted environments. If you create large user-defined complex data types, reserving array space ahead of processing time might also not be possible.

Being able to allocate, free, and reallocate memory is therefore vital in many applications. The two basic functions are malloc and free. The malloc function is defined as:

malloc ( <block size> )       // allocate a piece of memory

The function returns a void pointer, which can be cast to any type, including user-defined and complex data types. The <block size> parameter is usually a long integer, which may place a maximum block size on the memory that can be ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required