Parameter-Passing Methods

Parameter-passing semantics decide whether a callee receives a copy, an alias, or a copy-in/copy-out proxy for the caller's data.

The key question is what exactly crosses the call boundary.

Sebesta treats parameter passing as one of the deepest subprogram design decisions because it controls aliasing, side effects, and how much a callee can change the caller's state.

When to reach for this

Reach for this concept when you want to predict whether a subprogram can mutate caller data, whether two parameter names can alias the same storage, or why one language's function call behaves differently from another's.

Why this matters

A function call can look innocent in source code while hiding important memory behavior. Understanding pass-by-value, pass-by-reference, and value-result semantics explains many surprising bugs.

The mental model

Copies isolate the callee

If the callee receives its own slot, local changes do not automatically leak back to the caller.

Aliases couple caller and callee

If the callee receives another name for the same storage, side effects become immediate and visible outside the routine.

Step through the concept

How to use this page

Follow the animation one state at a time and connect the code to the runtime behavior.

  • Keep the caller value in view and compare it to the callee parameter on every step.
  • Notice which tabs create a copy and which create an alias.
  • Watch for the copy-out step because it is the entire point of value-result semantics.
Local copy firstCaller unchanged
Caller starts with score = 10Same function body, different call semantics
Caller frame
score
10
Lives in the caller.
Status

Caller owns score = 10.

call setup
Callee frame
n
Caller score exists before the call.
1void boost(int n) {
2 n = n + 5;
3}
4
5int score = 10;
6boost(score);
Mental model

Copies the argument into a local slot

Step 1 of 4
What
The caller has one variable: score = 10.
Why
Before the call, only the caller's memory exists. The callee will receive a copy, not the original slot.
Code for this pattern
void boost(int n) {
  n = n + 5;
}

int score = 10;
boost(score);

Each passing strategy answers the aliasing question differently

AspectPass by valuePass by referenceValue-result
What enters the calleeA copied valueAn alias to caller storageA copied value
When caller sees changesNeverImmediatelyAt return
Main benefitIsolationDirect mutationIsolation during call, update after
Main riskExtra copyingAliasing surprisesCopy-out surprises with shared targets

The short version

  • Parameter passing is a memory model decision, not just a syntax choice.
  • Pass by value protects the caller by isolating the callee in a copied slot.
  • Pass by reference exposes the caller slot directly, so side effects are immediate.
  • Value-result copies in first and copies out later, which changes when the caller sees updates.