Your Browser is not longer supported
Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...
{{viewport.spaceProperty.prod}}
&pagelevel(4)&pagelevel
Syntax | #include <stdlib.h> void *calloc(size_t nelem, size_t elsize); | |
Description | calloc() allocates unused memory space at execution time for an array of nelem elements, where the size of each element in bytes is elsize. calloc() initializes each element of the new array with binary zeros. calloc() is part of a C-specific memory management package that internally handles the requested and released memory areas. As far as possible, new requests are satisfied first from areas already being managed, and only then from the operating system.
nelem is an integer value that specifies the number of array elements. elsize is an integer value that specifies the size of an array element. If memory areas were assigned via successive calls of calloc() , the arrangement of these areas in the memory is undefined. The pointer that is returned if allocation is successful is aligned with a doubleword boundary, so that it can be assigned to a pointer to any type of object. After the assignment, the object or an array of such objects in the newly assigned memory area can be accessed (until the area is explicitly released or reassigned). |
Return val. | Pointer to the new memory space |
| if nelem and elsize are not 0 and sufficient memory is available. |
Null pointer | if the available memory does not suffice for the request.
errno is set to indicate the error. |
Errors | calloc() will fail if:
ENOMEM Insufficient memory is available.
|
Notes | The new data area begins on a doubleword boundary. To ensure that the correct size for an array element is requested, the sizeof operator should be used when calculating elsize. If the length of the allocated memory area is exceeded during writing, serious errors in the working memory may occur. calloc() is interrupt-protected, i.e. the function can be used in signal handling and contingency routines.
|
See also | free(), malloc(), realloc() , stdlib.h .
|