Consider the following statements S1, S2 and S3 : S1 : In call-by-value,…

2014

Consider the following statements S1, S2 and S3 :

S1 : In call-by-value, anything that is passed into a function call is unchanged in the caller’s scope when the function returns.

S2 : In call-by-reference, a function receives implicit reference to a variable used as argument.

S3 : In call-by-reference, caller is unable to see the modified variable used as argument.

  1. A.

    S3 and S2 are true.

  2. B.

    S3 and S1 are true.

  3. C.

    S2 and S1 are true.

  4. D.

    S1, S2, S3 are true.

Attempted by 356 students.

Show answer & explanation

Correct answer: C

Answer: S1 and S2 are true; S3 is false.

  • S1: In call-by-value the callee receives a copy of the argument, so reassigning the parameter does not change the caller's variable. Thus the caller's variable remains unchanged when the function returns.

  • S2: In call-by-reference the callee receives a reference to the caller's variable, so the function can modify the caller's variable directly.

  • S3: This is false: because call-by-reference lets the callee change the caller's variable, the caller can see those modifications.

Note: Some languages (for example Java) pass object references by value, which means the reference itself is copied; methods can mutate the referred object and those mutations are visible to the caller even though the parameter passing is technically call-by-value. This distinction does not change the general meanings of call-by-value and call-by-reference used above.

Explore the full course: Mppsc Assistant Professor