• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 6 páginas
Notas de lectura

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

Document preview thumbnail
Vista previa 2 fuera de 6 páginas

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.

Vista previa del contenido

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

Información del documento

Subido en
27 de noviembre de 2026
Archivo actualizado en
27 de noviembre de 2026
Número de páginas
6
Escrito en
2026/2027
Tipo
Notas de lectura
Profesor(es)
General / standard curriculum
Contiene
Todas las clases
$7.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
8
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes