CALLOC - allocate storage for array of elements.

(ANSI Standard)


#include <stdlib.h>
ptr = calloc( N, size );


size_t N;
is the number of elements in the array.
size_t size;
is the size of each element.
void *ptr;
points to the newly allocated array. The space begins at an alignment boundary that is suitable for storing objects of any data type. If an argument is improperly specified, the NULL pointer is returned.


"calloc" returns a pointer to space for an array of N elements, each of the given size. This space is initialized to zero bits, which will give zero values for an integer or pointer type, but not for floating point types.

Normally the size argument should be specified using the "sizeof" operator.


The ANSI standard requires that "calloc" return a NULL pointer if the desired amount of memory cannot be obtained. This doesn't happen with SS mode GCOS-8 -- if a program asks for more memory and is denied, the program is automatically aborted by the system. Thus, in SS mode, "calloc" will never return the NULL pointer.

See Also:

expl c lib malloc

expl c lib realloc

expl c lib free

Copyright © 1996, Thinkage Ltd.