Sunday, July 17, 2011

Dynamic Memory Allocation in C

Dynamic Memory allocation is the process of allocating memory to program in runtime.

The various dynmaic memory allocation functions available in C are
  • Malloc:Allocates specified number of bytes un memory and returns the pointer to the first byte allocated.

           pointer=(cast-type*)malloc(size in bytes)

  • Calloc:Creates more than one block of memory and returns the pointer to the first byte in the first block.
          pointer=(cast-type*) calloc(n,size in bytes)

          Here n refers to the number of blocks

  • realloc:Used to reallocate a previous allocated memory area.

           pointer=realloc(new pointer,newsize);

  • free:Used to clear previously allocated memory so that memory is used efficiently.

          free(pointer name);


Post a Comment


The Source Codes Published in this Blog can be used freely for Educational purposes but should not be reproduced on any other Blog or Website without the consent of the author.