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);

No comments:

Post a Comment

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...