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
§ 3.1.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 example: swapping by value vs by pointer
C passes arguments by value: a and b are copies, so x and y don't change.
↳ Result: x = 1, y = 2The pointers are copies, but they point at x and y, so writing through them changes the originals.
↳ Result: x = 2, y = 1Practice: test yourself
Original practice questions in the GATE style, with worked explanations. Not past-paper questions.
A function is tail-recursive when:
Which version of factorial is tail-recursive?
void inc(int *p) { (*p)++; } int x = 5; inc(&x); inc(&x); What is x?
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 for clarity, rigorous numerical solving, and semester excellence:
Systematic beginner-to-advanced C with clear examples.
Clear step-by-step C explanations — great for semester lab preparation.