


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Iqbal Mohomed
void
write(int
f)
{
//
Blah
} void
main()
{
int
a^
=^
3;
write
(a);
} •^
We call a the actual paramater
-^
We call f the formal parameter
that exists within the scope of theprocedure/function/subprogram
initialize the formal parameter
NOT get transmitted back to the callerthrough parameter passing!
are costly!
that exists within the scope of the function
the caller, the value of the formal paramteris transmitted back to the actual paramater
-^
Actual parameter MUST be a variable
-^
Parameter collisons can occur!– write(p1,p1); .. if the two formal parameters in write had different
names, which value should go into p1?
value!
-^
Typically implemented by copy– Inefficiency in storage allocation– inefficiency in copying value– For objects and arrays, the copy semantics are costly!– The added problem is that we don’t want to use the value of the
actual parameter as the initial value of the formal parameter
reliability
substituted for the corresponding formalparameter in all its occurances within thefunction
late-binding ... short-circuit evaluation is anexample of lazy evaluation
-^
C and Java both use pass-by-value semantics.
-^
People keep saying objects are treated as pass-by-reference in Java. Technically ... that isWRONG!
-^
C++ uses pass-by-value as the defaultconvention but allows pass-by-referenceparameters as well– the & operator is used to indicate pass-by-reference– e.g. void write(int& p){ ///}