The Gateway to Computer Science Excellence
+2 votes

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. $S3$ and $S2$ are true. 
  2. $S3$ and $S1$ are true.
  3. $S2$ and $S1$ are true. 
  4. $S1, S2, S3$ are true. 
in Compiler Design by Boss (30.2k points) | 668 views

3 Answers

+5 votes
Best answer

Answer : C

Call-By-Value : While Passing Parameters using call by value, copy of original parameter is created and passed to the called function.
Any update made inside method will not affect the original value of variable in calling function. For Example 


void interchange(int number1,int number2)
    int temp;
    temp = number1;
    number1 = number2;
    number2 = temp;

int main() {

    int num1=50,num2=70;

    printf("\nNumber 1 : %d",num1);
    printf("\nNumber 2 : %d",num2);


In the above example num1 and num2 are the original values and copy of these values is passed to the function and these values are copied into number1,number2 variable of interchange function respectively.
As their scope is limited to only function they cannot alter the values inside the caller function.

Call-By-Reference : This method copies the address of an argument into the formal parameter. This means that changes made to the parameter affect the original argument.


void interchange(int &num1,int &num2)
    int temp;
    temp  = num1;
    num1 = num2;
    num2 = temp;

int main() {

    int num1=50,num2=70;

    printf("\nNumber 1 : %d",num1);
    printf("\nNumber 2 : %d",num2);



C uses call by value to pass arguments while C++ has both call by value and call by reference. C can simulate call by reference by passing pointers as value- but this is also technically call by value, as pointer value is copied and passed.        

by Boss (45.3k points)
selected by
+4 votes

Answer is C) S2 and S1 are true

S3 is false, because in call-by-reference caller always sees the modified value of the argument .

by Veteran (50.7k points)
0 votes
Answer C
by Boss (32.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
50,647 questions
56,492 answers
100,778 users