GATE 2001 | Parameter Passing What is printed by print statements in the program P1 assuming call by referencβ¦
ravikaranrathore
GATE 2001 | Parameter Passing
What is printed by print statements in the program P1 assuming call by reference parameter passing?
Program P1(){
x = 10;
y = 3;
func1(y,x,x);
print x;
print y;
}
func1(x,y,z){
y = y+4; // line 1
z = x+y+z; // line 2
}
A. 10,3 B. 31,3 C. 27,3 D. None of the above
So, in this the comments are marked by my. and catch is there only for correct answer.
AI mentor says answer is C, answer key gave ans. B
when i said the same to AI mentor, it also changed its answer.
Pls without using AI tell me actual rule,
line 1, will update local y value and since this local y is referenced to x in program p1, hence x is also updated to 14.
line 2, z = 3 + 14 + z
what value of z we use now,, since when parameters were passed z was initialised as 10 (by x from p1),, now when y updated x in line 1,, It should not affect z here right?
but answer key's correct answer come, when we use updated value.
AI is causing more confusion, so please give me resource of the rule too.
Thanks.
