• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 6 pages
Class notes

C Programming Comprehensive Lecture Notes: Modular Functions, Runtime Call Stack, Recursion & Storage Classes

Document preview thumbnail
Preview 2 out of 6 pages

Extensive university-grade C Programming Module 03 lecture notes for Computer Science students. Includes formal modular design principles, stack frame memory architecture, parameter evaluation order, mathematical recurrence analysis, recursion tree tracing, storage duration and linkage rules, and fully solved university examination programs.

Content preview

UNIVERSITY LECTURE SERIES • COMPUTER SCIENCE CORE CURRICULUM


MODULE 03: MODULAR FUNCTIONS, CALL
STACK ARCHITECTURE, RECURSION &
STORAGE CLASSES
Course: B.Sc. / B.Tech. Computer Science | Standard: ISO/IEC 9899 (C99 / C11)




1. Procedural Decomposition & Modular Software Design
In systems engineering, complex algorithms are partitioned into cohesive, reusable
subroutines called functions. Modular decomposition achieves three architectural
objectives:
Abstraction & Encapsulation: Callers interact strictly through a documented function
signature without depending on internal implementation details.
Elimination of Code Duplication: Shared computational routines are compiled once in
the text segment and invoked from multiple call sites.
Isolated Verification: Individual functions can be unit-tested independently before
system integration.
1.1 Function Prototypes & Type Checking
In ANSI C89/C99/C11, every function must be declared via a function prototype prior to
its first invocation. The prototype specifies the return type and parameter list:
// Prototype declarations in header file (math_utils.h)
int is_prime(int candidate);
void swap_integers(int *first, int *second);
Void Parameter List Distinction: In C, int func(void); explicitly declares a function
accepting zero arguments, whereas int func(); declares an obsolete K&R-style
prototype accepting an unspecified number of arguments.

2. Process Memory Layout & Call Stack Mechanics
When the operating system loads a compiled C executable into virtual memory, the
address space is segmented into five distinct regions:
±----------------------------------+ High Virtual Address (0x7fffffffffff)
| CALL STACK | Grows downward; stores local auto variables,
| (Activation Records / Frames) | parameters, and return addresses
±----------------------------------+
|||

,|v|
| (Free Space) |
|^|
|||
±----------------------------------+
| HEAP | Grows upward; dynamic allocation (malloc/free)
±----------------------------------+
| BSS SEGMENT (.bss) | Uninitialized global & static variables (zeroed)
±----------------------------------+
| DATA SEGMENT (.data) | Initialized global & static variables
±----------------------------------+
| TEXT SEGMENT (.text) | Read-only compiled machine instructions
±----------------------------------+ Low Virtual Address (0x000000400000)
2.1 Anatomy of a Stack Frame (Activation Record)
When caller() invokes callee(a, b) , the CPU executes the following low-level sequence:
Arguments a and b are placed into CPU registers (System V AMD64 ABI: %rdi , %rsi ,
%rdx , %rcx , %r8 , %r9 ) or pushed onto the stack.
The CALL instruction pushes the Return Address (the instruction immediately
following the call) onto the stack and jumps to callee .
The function prologue saves the caller’s Base Pointer ( %rbp ) and decrements the Stack
Pointer ( %rsp ) to reserve space for local auto variables.
Upon encountering return , the epilogue restores %rsp and %rbp , and the RET
instruction pops the return address back into the Instruction Pointer ( %rip ).

3. Parameter Passing: Value vs. Pointer Indirection
#include <stdio.h>

// Pass-by-Value: Operates on local copies; caller variables unaffected
void attempt_swap_by_value(int x, int y) {
int temp = x;
x = y;
y = temp;
}

// Pass-by-Address: Dereferences pointers to mutate caller memory directly
void swap_by_address(int *px, int *py) {
int temp = *px;
*px = *py;
*py = temp;
}

Document information

Uploaded on
November 27, 2026
File latest updated on
November 27, 2026
Number of pages
6
Written in
2026/2027
Type
Class notes
Professor(s)
General / standard curriculum
Contains
All classes
$7.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
8
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions