PROGRAMMING IN C/Student Engineering Notebook
Page 06·notes
FUNCTIONS, RECURSION & THE CALL STACK—~28 MIN READ

Parameter Passing (Value vs Pointer) & Tail Recursion

“Call-by-value semantics, simulating call-by-reference via pointers, and tail call elimination.”

1.Parameter Passing Semantics: Pure Call-by-Value

C strictly supports Call-by-Value ONLY:

- When an argument is passed to a function, the function receives a copy of the value.

- Modifying a parameter inside the function has zero effect on the caller's original variable.

Simulating Call-by-Reference:

- To modify caller variables, pass the memory address of the variable (pointer).

- Even then, the pointer itself is passed by value (a copy of the address is pushed onto the stack)!

WORKED NUMERICAL · STUDENT DERIVATION✎ Key Takeaway: C has only call by value. 'Pass by reference' in C means passing a pointer by value.

Worked example: swapping by value vs by pointer

Problem Statement:
void s1(int a, int b) { int t = a; a = b; b = t; } void s2(int a, int b) { int t = a; a = b; b = t; } With x = 1 and y = 2, compare s1(x, y) and s2(&x, &y).
Step 1: s1

C passes arguments by value: a and b are copies, so x and y don't change.

↳ Result: x = 1, y = 2
Step 2: s2

The pointers are copies, but they point at x and y, so writing through them changes the originals.

↳ Result: x = 2, y = 1
Final Answer:s1 leaves x and y unchanged; s2 swaps them
STUDENT PRACTICE · CONCEPT DRILL

Practice: test yourself

Original practice questions in the GATE style, with worked explanations. Not past-paper questions.

Problem 1 · FOUNDATION

A function is tail-recursive when:

Problem 2 · GATE-LEVEL

Which version of factorial is tail-recursive?

Problem 3 · FOUNDATION

void inc(int *p) { (*p)++; } int x = 5; inc(&x); inc(&x); What is x?

SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Curated University Lecture Series
The C Programming Language (2nd Edition) ·
LECTURE SERIES
RECOMMENDED YOUTUBE EDUCATORS & FULL-COURSE PLAYLISTS

Curated for clarity, rigorous numerical solving, and semester excellence:

Neso Academy · C Programming Full Course↗Instructor: Neso Academy · Covers: Data types, pointers, arrays, functions, recursion, file I/O

Systematic beginner-to-advanced C with clear examples.

Open YouTube↗
Jenny's Lectures CS/IT · C Programming↗Instructor: Jenny's Lectures · Covers: Arrays, strings, pointers, structures, file handling, preprocessor

Clear step-by-step C explanations — great for semester lab preparation.

Open YouTube↗