calloc()                 Allocate and Zero Memory
 
 #include   <malloc.h>                   Required for declarations only
 
 char       *calloc(n,size);
 unsigned   n;                           Number of elements to allocate
 unsigned   size;                        Number of bytes in each element
 
    calloc() allocates storage for 'n' elements of 'size' bytes each.
    All elements are initialized to 0.  The storage space is guaranteed
    to be correctly aligned for any data type.
 
 
    Returns:    Char pointer to the allocated space, or NULL (defined in
                <stdio.h>) if the space cannot be allocated.
 
      Notes:    Memory allocated with calloc() should only be freed with
                free().
 
                To get a pointer to a type other than char, use a type
                cast on the return value.
 
  -------------------------------- Example ---------------------------------
 
    The following statements allocate space for 50 long integers and then
    free the allocated space.
 
           #include <malloc.h>
           #include <stdio.h>      /* for printf and NULL */
 
           long *memptr;
 
           main()
           {
               if ((memptr = (long *) calloc(50, sizeof(long))) == NULL)
                    printf("not enough room to allocate memory\n");
               else {
                    .
                    .
                    free(memptr);
                }
            }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster