Call-by-reference-and-Call-by-value
Question 1 |
In which one of the following cases is it possible to obtain different results for call-by reference and call-by-name parameter passing methods?
Passing a constant value as a parameter | |
Passing the address of an array as a parameter | |
Passing an array element as a parameter | |
Passing an array following statements is true
|
Question 1 Explanation:
Passing an array element as a parameter then it gives different output values for the call-by-reference and call-by-name parameters.
{ ........
a[ ] = {1, 2, 3, 4}
i = 0
fun(a[i]);
print a[0];
}
fun(int x)
{
int i = 1;
x = 8;
}
O/p:
Call-by-reference = 8
Call-by-value = 1
{ ........
a[ ] = {1, 2, 3, 4}
i = 0
fun(a[i]);
print a[0];
}
fun(int x)
{
int i = 1;
x = 8;
}
O/p:
Call-by-reference = 8
Call-by-value = 1
There is 1 question to complete.