STORAGE CLASSES
Course: Bachelor of Science / Engineering in Computer Science | Module 03:
Comprehensive Summary & Reference Sheet
1. Modular Function Architecture & Three-Part Lifecycle
A function is an independent, self-contained block of executable code designed to
perform a specific computational task. Every user-defined function follows a strict three-
part lifecycle:
// 1. FUNCTION PROTOTYPE (Declaration - informs compiler of signature)
double compute_power(double base, int exponent);
int main(void) {
// 2. FUNCTION CALL (Transfers control & passes actual arguments)
double result = compute_power(2.5, 3);
return 0;
}
// 3. FUNCTION DEFINITION (Contains formal parameters & implementation)
double compute_power(double base, int exponent) {
double acc = 1.0;
for (int i = 0; i < exponent; i++) {
acc *= base;
}
return acc;
}
Component
Syntactic Role
Compiler Verification
Function Prototype
Declares return type, identifier, and parameter types; ends with ;
Enables static type-checking before definition
Actual Arguments
Expressions evaluated at the call site and copied into parameters
Must match prototype arity and compatible types
Formal Parameters
,Local stack variables initialized with incoming argument values
Scoped strictly to the function body
Return Statement
Terminates execution and yields a value matching the return type
Implicitly cast to declared return type if compatible
2. Parameter Passing Semantics: Pass-by-Value vs. Pass-by-Address
Strictly speaking, C supports only Pass-by-Value. Reference semantics are simulated
explicitly by passing memory addresses (pointers) by value.
Architectural Criterion
Pass-by-Value (Default)
Pass-by-Address (Pointer-Based)
Data Transmitted
Copy of the variable’s stored value
Copy of the variable’s RAM address ( &var )
Caller State Mutation
Protected (Immutable) — caller remains unchanged
Mutable — dereferencing ( *ptr ) modifies caller RAM
Memory Overhead
Duplicates full object size on the stack
Fixed pointer width (8 bytes on 64-bit systems)
Primary Use Case
Pure mathematical computations, scalar inputs
In-place mutation, returning multiple outputs, arrays
3. Runtime Call Stack & Activation Records
Every active function invocation pushes an Activation Record (Stack Frame) onto the
process Call Stack (LIFO architecture):
±------------------------------------------------------+ <-- High Memory Address
| main() Stack Frame: [ x = 10 ] [ y = 20 ] |
±------------------------------------------------------+
| swap(&x, &y) Frame: [ a = 0x7ff0 ] [ b = 0x7ff4 ] |
| [ Return Address -> main()+24 ] |
±------------------------------------------------------+ <-- Stack Pointer (%rsp)
Frame Contents: Saved return instruction address, formal parameters, local automatic
variables, and saved CPU base pointer ( %rbp ).
Stack Overflow Condition: Occurs when unbounded recursion exhausts the fixed OS
stack segment (typically 1 MB – 8 MB), triggering a fatal segmentation fault.
4. Recursion Mechanics & Structural Classification
A recursive function solves a problem by reducing it to smaller self-similar
subproblems. Every valid recursive algorithm requires two mandatory clauses: