edited by
504 views
5 votes
5 votes

Consider the following code snippet.

void first(int p, int t)
{
    p +=  t;
    t +=  p;
}

main()
{
    int p = 4;
    first(p , p);
}

What is the final value of $p$ in both call by value and call by reference respectively ?

  1.   $4$ and $12$ 
  2.    $5$ and $12$  
  3.    $12$ and $16$  
  4.    $4$ and $16$
edited by

1 Answer

Best answer
7 votes
7 votes
In call by value, function first() operate on copy of p, hence value of p remains unchanged.

In call by reference, first value of p changes to 4+4, then it changes to 8+8, hence 16.
selected by
Answer:

Related questions

13 votes
13 votes
6 answers
2
Kathleen asked Oct 8, 2014
7,057 views
What is the value of $X$ printed by the following program?program COMPUTE (input, output); var X:integer; procedure FIND (X:real); begin X:=sqrt(X); end; begin X:=2 FIND(...