Home

byvalue

By value is a parameter passing convention in programming languages in which a function receives a copy of the actual argument's value. The callee operates on that copy, and changes to the parameter do not affect the original variable in the caller.

How it behaves depends on the language and the type being passed. For primitive or value types,

Because by-value copies create a distinct copy, the callee has its own storage and cannot alter the

Trade-offs include performance costs for large data structures due to copying, and the potential loss of in-place

Examples:

- In C-like pseudocode, void f(int x) { x = x + 1; } int a = 5; f(a); // a remains 5

- In languages where objects are passed by value of the reference, such as some interpretations of

See also: pass by reference, copy semantics, shallow copy, deep copy, value type, reference type.

the
language
typically
copies
the
entire
value.
For
reference
types,
some
languages
copy
the
reference
rather
than
cloning
the
object,
so
the
function
can
mutate
the
shared
object,
while
others
copy
the
object
itself
if
it
is
a
value
type.
caller’s
data
by
assigning
to
the
parameter.
This
makes
reasoning
about
code
easier
and
can
aid
predictability
and
thread
safety,
since
the
caller’s
state
is
not
directly
mutated
by
the
callee.
updates.
Modern
languages
mitigate
these
costs
with
techniques
such
as
move
semantics,
copy-on-write,
or
by
returning
modified
values
rather
than
modifying
inputs.
Java,
a
function
may
receive
a
copy
of
the
reference;
the
underlying
object
may
still
be
mutated
if
it
is
mutable.