...
Question 10596 – GATE 1987
May 8, 2024
Question 10576 – GATE 1989
May 8, 2024
Question 10596 – GATE 1987
May 8, 2024
Question 10576 – GATE 1989
May 8, 2024

Question 10575 – GATE 1989

In which of the following case(s) is it possible to obtain different results for call-by-reference and call-by-name parameter passing?

Correct Answer: E

Question 2 Explanation: 
Option D:
Passing array element as a parameter.
Consider an example:
{
…….
a[ ] = {1, 2, 3, 4, 5}
fun (a[i]);
print a[0];
}
fun (int x)
{
int i=1;
}
O/P:
Call-by-reference: 6
Call-by-name: 1
Result is different.
Option A:
While we passing an expression as a parameter due to precedence (higher (or) lower), the output may changes.
If we pass 1+2 to the below function
int foo (int x)
{
return x*x;
}
O/P:
Call by reference = 3*3 = 9
Call by name = 1+2*1+2 (* has higher precedence
e)
= 1+2+2
= 5
Output differs.
Answer: A, D
A
Passing an expression as a parameter
B
Passing an array as a parameter
C
Passing a pointer as a parameter
D
Passing as array element as a parameter
E
Both A and D
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!