11 votes 11 votes Consider the following program Program P2 var n : int; procedure W(var x : int) begin x = x + 1; print x; end procedure D begin var n : int; n = 3; W(n); end begin \\begin P2 n=10; D; end If the language has dynamic scooping and parameters are passed by reference, what will be printed by the program? 10 11 3 None of the above Programming in C gatecse-2001 programming parameter-passing normal out-of-syllabus-now + – Kathleen asked Sep 14, 2014 edited Oct 26, 2016 by go_editor Kathleen 7.3k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 16 votes 16 votes answer is D. here, because of dynamic scoping the value of n passed in w(n) will be n=3. therefore o/p will be 4, which is not in any option. jayendra answered Jan 1, 2015 edited Sep 1, 2023 by Hira Thakur jayendra comment Share Follow See all 3 Comments See all 3 3 Comments reply Nitika Gupta commented Nov 19, 2017 reply Follow Share dynamic scoping part is understood by me the answer will be 4..but does parameters are passed by reference mean the below when converted to C language. int n; W(int *x) {*x = *x + 1; print *x;} D(){int n; n = 3; W(&n); } main(){n=10; D(); } 0 votes 0 votes rahul sharma 5 commented Nov 28, 2017 reply Follow Share You are correct Nitika Gupta.Internally how it will change it does not matter,What matters in the actual value of n will be changed by which is passed by D to W Also, in the answer it says that here, because of dynamic scoping the value of n passed in w(n) will be n=3. I dont think dynamic scoping will have any role here,because as long as we have local variable(x),it will be used.Scoping comes into picture,when variable getting used is not defined in the scope of the function which is using it. 4 votes 4 votes yagneshmb commented Jun 9, 2020 reply Follow Share Even if you run it in C, the answer will be 4. C uses static scoping if anyone wants to check. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes It print 4 , which is not in option, So correct option is D Navneet singh answered Oct 23, 2019 Navneet singh comment Share Follow See all 0 reply Please log in or register to add a comment.