#include <stdlib.h>void *malloc(size_t size);

The malloc( ) function returns a pointer to the first byte of a region of memory of size size that has been allocated from the heap. If there is insufficient memory in the heap to satisfy the request, malloc( ) returns a null pointer. It is always important to verify that the return value is not null before attempting to use it. Attempting to use a null pointer will usually result in a system crash.

Related functions are free( ), realloc( ), and calloc( ).

Programming Tip 

If you are writing 16-bit programs for the 8086 family of processors, then your compiler will provide additional allocation functions that accommodate the segmented memory used by these processors when operating in 16-bit mode. For example, there will be functions that allocate memory from the FAR heap (the heap that is outside the default data segment), that can allocate pointers to memory that is larger than one segment, and that free such memory.

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539 © 2008-2017.
If you may any questions please contact us: