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 - realloc http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   realloc

   Usage
   #include <stdlib.h>
   void *realloc (void *ptr,size_t size);

   Description
   realloc  changes  the  size of a  previously  allocated  memory  block
   pointed to by ptr. The size of the block after the call to realloc  is
   specified  by size. If size is 0, ptr is free'd and NULL is  returned.
   If  ptr is NULL, then size is malloc'd and the result is returned.  If
   there  is  insufficient room to expand the current block a  new  block
   will  be allocated and the current block released. Existing data  will
   be copied into the new block.

   Example
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   main()
   {
   char *ptr;
        ptr = realloc(NULL,20*sizeof(char));
        strcpy(ptr,"This is part one, ");
        ptr = realloc(ptr,100*sizeof(char));
        strcat(ptr,"This is part two.");
        printf("\%s\n",ptr);
        realloc(ptr,0)
   }

   Return Value
   A  pointer  to the reallocated memory block is returned. If  there  is
   insufficient memory for the realloc, NULL is returned (but ptr is  not
   free'd).


See Also: calloc free malloc

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