Malloc
malloc is a C standard-library function that allocates a specified number of bytes of uninitialized storage and returns a pointer to it or a null pointer if allocation fails.
Modern C, Third Edition
malloc is a C library function that allocates a specified number of bytes of uninitialized storage and returns a pointer to it or a null pointer on failure.
- How it is used
- Allocates storage for variable-sized arrays and circular buffers when fixed-size arrays are too restrictive.
- How deep it goes
- Works through sizing, failure checks, and release constraints without describing allocator internals.
- Examples
- Uses a variable-sized double array, a string-copying strdup sketch, and a resizable circular buffer.
- What you can do after
- Practice/perform variable-sized allocation with null checks, initialization, and matching deallocation.
Modern C
malloc is the C standard library function that allocates a specified number of bytes of storage and returns a pointer to the storage or a null pointer on failure.
- How it is used
- Deploys malloc for storage whose size or lifetime must vary during execution.
- How deep it goes
- Explains byte sizing, void pointers, allocation pairing, and valid free arguments, but defers implementation internals.
- Examples
- Uses a vector of doubles sized for one element per living person and examines platform feasibility.
- What you can do after
- Apply malloc to allocate byte-sized storage and maintain its lifetime with a valid matching free.
Related concepts
- freeuses · free is a C standard-library function that releases dynamically allocated storage previously obtained from a compatible allocation function.
- callocalternative to · calloc is a C standard-library function that allocates contiguous storage for an array of elements and initializes all allocated bytes to zero.
- reallocincludes · realloc is a C standard-library function that changes the size of an allocated memory block while preserving its existing contents up to the applicable size.
- C standard libraryproduced by · The C standard library is the standardized collection of functions, macros, types, and related facilities provided for C programs.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

