From the course: Master C Language Pointers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Exploring allocation functions

Exploring allocation functions - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

Exploring allocation functions

- Here are four memory allocation functions from the standard C library, each of which deals with memory allocation and pointers, malloc(), calloc(), realloc() and free(). The malloc() function allocates uninitialized storage just like any variable or array in C. The calloc() function on the other hand, allocates and initializes memory, for numeric storage values are set to zero for character storage, values are set to the NULL character. The realloc() function dynamically resizes an existing buffer, for example, making it larger. The contents of the old buffer are copied to the new buffer as much as possible, and yes it's possible to resize an existing buffer by specifying it's pointer as both the function's first argument and as the return value. As with the malloc() function, the realloc() function doesn't initialize the added storage. The free() function is used on an allocated buffer to recover the memory and allow…

Contents