Lab 08 -- C Programming - Recursion, Struct and Dynamic Memory Allocation
This page gives an overview of the lecture and the lab session on Sep 18, 2025.
Short lecture summary
-
Function declaration and definition. Scope of variables. Local and global scope. Recursion, function calls, stack area and stack frame.
-
Calling conventions - call by value and call by reference mechanisms
-
User-defined types -
struct. Usage and examples. -
Dynamic memory allocation. Heap area of memory.
malloc()andfree()function. Importance of free call in preventing memory leaks. -
Using math libraries and the need to compile using
-lmoption.
Readings
-
Notes on C programming by Jasine.
These notes are based on the lectures for the course CS1100 Introduction to Programming (Aug-Dec 2016) offered at IIT Palakkad. You can find a link to the complete set of notes here.
Read Lectures
-
C Programming A Modern Approach (2nd Ed) by K. N. King (Online version)
Read chapters
Practise
-
Work out the problems in
exercisesfolder oflab08in thegitserverrepo. Also fix the issues in all the c files appearing inerrordirectory. -
Puzzles on C programming. Work out Part SL, Part 2D and Part T from this link.
Additional readings
-
Pointer arithmetic is a necessary skill to learn GPU programming. Check the slides by Will Landau. The code appearing the slides is available here.
-
Notes by Dave Marshall on dynamic memory allocation.
-
C programming guide by Beej Jorgensen.
-
Chapter 9.9 - Dynamic Memory Allocation Computer Systems: A Programmer’s Perspective, third edition
-
Chapter 9.11 - Common memory related bugs in C programs Computer Systems: A Programmer’s Perspective, third edition
