Review:
parameter passing mechanisms
- Recall that the
2 commonly used
parameter passing mechanisms are:
- Pass-by-value
- The
value of the
actual parameter variable is
copied into the
formal parameter variable
|
Without its
address, the
function
cannot
update (= change) the
actual parameter variable
- Pass-by-reference
- The
reference (= memory address) of the
actual parameter variable is
copied into the
formal parameter variable
|
Using its
address, the
function
can
update (= change) the
actual parameter variable !
|
|
The
parameter passing mechanism used
in C
Example that shows
C uses
pass-by-value
DEMO:
demo/C/set1/pass-by-value1.c
Why
is a
pass-by-value parameter
not updated
Why
is a
pass-by-value parameter
not updated
- When main( )
starts running,
it first
creates (= allocates)
the local variable
a:
|
Why
is a
pass-by-value parameter
not updated
Why
is a
pass-by-value parameter
not updated
Why
is a
pass-by-value parameter
not updated
Looking ahead:
C can pass
variable by reference
Why
is a
pass-by-reference parameter
updated
Why
is a
pass-by-reference parameter
updated
- When main( )
starts running,
it first
creates (= allocates)
the local variable
a:
|
Why
is a
pass-by-reference parameter
updated
Why
is a
pass-by-reference parameter
updated
Why
is a
pass-by-reference parameter
updated
❮
❯