The Default Parameter Passing Mechanism is called as
2012
The Default Parameter Passing Mechanism is called as
Answer: A. Call by Value — A parameter-passing mechanism fixes what a called routine actually receives for each argument: a copy of the argument's value, an alias for the caller's…
- A.
Call by Value
- B.
Call by Reference
- C.
Call by Address
- D.
Call by Name
Attempted by 131 students.
Show answer & explanation
Correct answer: A
A parameter-passing mechanism fixes what a called routine actually receives for each argument: a copy of the argument's value, an alias for the caller's storage cell, the address of that cell, or the argument's unevaluated expression. Under the copying discipline the callee works inside its own private storage cell, so nothing it assigns to a parameter can travel back into the caller.
The mechanism a language applies when nothing extra is written on a parameter is call by value. C evaluates every argument and hands the callee a copy of the resulting value; passing a pointer is no exception, because the address itself travels as a copied value. C++ and Java follow the same rule (Java copies the object reference into the parameter), and Pascal needs the word var written on a parameter before it departs from copying.
Contrast that with the three other disciplines named here:
Call by reference binds the parameter as an alias for the caller's storage cell, so an assignment made inside the callee is seen by the caller; Pascal writes this as var and C++ writes it as &.
Call by address hands over the cell's address as a pointer that the callee must dereference before it can touch the caller's data, so the pointer value itself is still copied into the callee.
Call by name substitutes the argument's expression at every use site inside the body and re-evaluates it each time, the ALGOL 60 thunk rule that makes Jensen's Device possible.
Hence the mechanism a language applies by default is call by value.