Skip to content
Official PYQ · 2002

GATE CS 2002 Q1.18 — Programming in C

Explain with AI

The results returned by function under value-result and reference parameter passing conventions

Choose one option
View worked solution

Answer: D

To understand why the results may differ, let us analyze how both parameter-passing conventions behave:

  1. Call-by-Reference: The formal parameter acts as an alias to the actual parameter (they share the same memory location). Any write operation to the formal parameter immediately updates the actual parameter.
  2. Call-by-Value-Result: The formal parameter is a local copy of the actual parameter. All operations during the function execution are performed on this local copy. The final value of the local copy is written back (copied) to the actual parameter only upon normal termination of the function.

If an exception occurs during the execution of the function:

  • Under call-by-reference, any modifications made before the exception was thrown are already permanently reflected in the actual parameters.
  • Under call-by-value-result, because the function terminates abnormally due to the exception, the copy-back step is typically not executed. Thus, the actual parameters retain their original values.

Hence, the results (the state of the actual parameters after the function call) may differ in the presence of an exception.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions