The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+10 votes

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

  1. Do not differ
  2. Differ in the presence of loops
  3. Differ in all cases
  4. May differ in the presence of exception
asked in Programming by Veteran (52.1k points)
retagged by | 2.1k views

2 Answers

+23 votes
Best answer

D. May differ in the presence of exceptions.

In call by reference, the called function is working with the memory location of the passed variables. So, any update to the variables are immediately effective.

In call by value-result, the called function is working with a copy of the passed variables. On return, the updated values are copied back to the original variables. 

So, during a function execution if an exception happens, in call-by-value-result, the passed variables won't be getting updated values. 

answered by Veteran (414k points)
selected by

Even in case of varaible when it used more number of times 

then also it give diff results as comapred to call by ref

so will i count Aliasing as an excpetion?

@arjun sir 

No. Aliasing is not exception. But with aliasing how the answer is differing for the two calls? Here, we are considering only the return value.
okay ,the answer by call be ref is 7 and with call by value result is 4 .

Here inspite of both x and a are same but they behave diff .

in the answer provided he has given how the ref run and CBV runs !
Yes, it can differ for aliased variables - but where is that code given?
code is inside stackexchange link
What is meaning of exception
any example plz??
@Arjun Sir  What is meant by exception .. example please
+1 vote
Answer should be B.

Call by value result and call by reference may differ in the presence of aliasing (sending the same parameter more than once).
answered by Active (1.5k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,811 questions
54,533 answers
75,553 users