Home

Callbyvalue

Call-by-value, sometimes written as callbyvalue, is a parameter passing convention used by some programming languages. Under this model, a function receives copies of the actual arguments rather than references to them. The callee works with its own local copies, and any modifications to those copies do not affect the caller’s original variables unless a return value communicates the result back.

In call-by-value languages, arguments are typically evaluated before the function body executes. The resulting values are

Advantages of call-by-value include simplicity and safety: the caller’s data cannot be altered unintentionally by the

Examples and notes: in C, function parameters are passed by value for most types, so a changed

then
bound
to
the
function’s
parameters.
If
an
argument
is
a
primitive
type
(such
as
an
integer
or
floating-point
number),
the
function
manipulates
only
the
copy.
If
an
argument
is
a
reference
to
an
object,
the
reference
itself
is
copied,
so
the
callee
can
mutate
the
object
through
that
copied
reference,
but
it
cannot
rebind
the
caller’s
variable
to
a
new
object.
callee,
making
reasoning
about
code
easier.
Drawbacks
include
potential
performance
costs
from
copying
large
data
structures
and,
in
some
languages,
the
need
to
implement
deep
copies
to
avoid
shared
mutations.
parameter
within
the
function
does
not
affect
the
caller’s
variable.
In
Java,
all
arguments
are
passed
by
value
of
the
reference,
so
a
function
can
mutate
the
object
referred
to
by
the
argument
but
cannot
rebind
the
caller’s
variable
to
a
new
object.
Call-by-value
is
often
contrasted
with
call-by-reference
and
with
more
exotic
schemes
such
as
call-by-name
or
copy-restore.