Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - calloc http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   calloc

   Usage
   #include <stdlib.h>
   void *calloc(size_t numelems, size_t sizelem);

   Description
   Allocates a block of memory that is numelems *sizelem bytes in size in
   the  program  heap.  The  memory  is  cleared  (i.e.  all  bytes   are
   initialized  to zero) and a pointer to it is returned. If there is  an
   error (e.g. insufficient memory), NULL is returned. If either numelems
   or sizelem is 0, NULL is returned. The block of memory requested  must
   be less than 64K.

   Memory is dynamically allocated from the heap at run time, and must be
   freed explicitly if the space is required again within the program.

   Example
   /* compile with C or L model */

   #include <stdlib.h>
   #include <stdio.h>
   #include <dos.h>
   #define num 50
   main()
   {
   long *buffer;
   unsigned int segment,offset;
        buffer = calloc(num,sizeof(long));
        if(!buffer)
        {
             fprintf(stderr,"Calloc failed\n");
             abort();
        }
        segment = FP_SEG(buffer);
        offset = FP_OFF(buffer);
        printf("Memory allocated at segment:%x offset:%x\n",
                segment,offset);
        free(buffer);
   }

   Return Value
   A pointer to the allocated memory is returned on success, otherwise  a
   NULL pointer is returned.


See Also: free malloc realloc farcalloc

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson