The effective result is the allocation of an zero-initialized memory block of (num * size) bytes.
Parameters
- num
- Number of elements to be allocated.
- size
- Size of elements.
Return Value
A pointer to the memory block allocated by the function.The type of this pointer is always void*, which can be cast to the desired type of data pointer in order to be dereferenceable.
If the function failed to allocate the requested block of memory, a NULL pointer is returned.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
This program simply stores numbers and then prints them out. But the number of items it stores can be adapted each time the program is executed because it allocates as much dynamic memory as needed during runtime.
See also
| free | Deallocate space in memory (function) |
| malloc | Allocate memory block (function) |
| realloc | Reallocate memory block (function) |
