H Lecture Notes - Lecture 8: C Dynamic Memory Allocation
Document Summary
In some situations, data is dynamic in nature. Number of data item keeps changing during program execution. Dynamic memory allocation: ability of a program to use more memory space at execution time. Memory space required can be specified at the time of execution. C supports allocating and freeing memory dynamically using library routines. The library has functions responsible for dynamic memory management. Allocates the memory of requested size and returns the pointer to the first byte of allocated space. The pointer returned is usually of type void. It means that we can assign malloc function to any pointer. Syntax : ptr = (type *) malloc (byte_size); This function is used to allocate multiple blocks of memory. It is a dynamic memory allocation function which is used to allocate the memory to complex data structures such as arrays and structures. syntax : ptr = (type *) calloc (n, byte_size); It is used to modify the size of previously.