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++ 3.0r4 - <b>calloc</b> 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);

   ANSI

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. If, under MS-DOS, a block of memory larger than 64K
   is required, the X memory model should be used.

   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 

   #include <stdlib.h>
   #include <stdio.h>
   #include <dos.h>
   #define num 50

   /* compile with a large data model */
   int main()
   {
       long *buffer;
       buffer = calloc(num,sizeof(long));
       if(!buffer)
           {
               fprintf(stderr,"Calloc failed\n");
               abort();
           }
       printf("Memory allocated at offset: %x\p",buffer);
       free(buffer);

       return EXIT_SUCCESS;
   }

Return Value

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

See Also

   free, malloc, realloc, farcalloc



See Also: free malloc realloc farcalloc

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