BTech First Semester - C Programming
Instructor: Mohsin F. Dar
Designation: Assistant Professor
Department: Cloud & Software Operations Cluster | SOCS
University: UPES
✓ Auto managed
✓ Fixed size
✓ Fast access
✓ Manual control
✓ Dynamic size
✓ Flexible
| Function | Purpose | Initialization | Parameters |
|---|---|---|---|
| malloc() | Allocate memory | Garbage values | 1 - Total size in bytes |
| calloc() | Allocate & initialize | Zero (0) | 2 - Count and size |
| realloc() | Resize memory | Preserves old data | 2 - Pointer and new size |
| free() | Deallocate memory | N/A | 1 - Pointer to free |
Write a program to dynamically allocate memory for n integers, input values, find their sum, and free the memory.
Dynamically allocate a 2D matrix of size m×n, input values, display the matrix, and free all allocated memory.
Create a dynamic array of strings to store n names. Input the names, sort them alphabetically, display, and free memory.
Start with an array of 5 elements. Take user input to add more elements. Use realloc() to expand the array as needed.
Create a dynamic array of Employee structures with fields: ID, Name, Salary. Implement add, display, and delete operations.
Lecture 21 - Unit V
Dynamic Memory Management
malloc() • calloc() • realloc() • free()
Mohsin F. Dar
Assistant Professor
Cloud & Software Operations Cluster | SOCS
UPES
Next Lecture: More topics from Unit V