4 4 votes Indicate results of the following program if the language uses i)Static scope rule and ii) Dynamic scope rules (GATE-1989) var x,y:integer; procedure A(var z:integer); var x:integer; begin x:=1; B; z:=x; end; procedure B; begin x:=x+1; end; begin x:=5; A(y); write(y) end; Programming in C + – Aspi R Osa 2.7k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
3 3 votes If call by value is used. It must be 0 in both the cases. Since, Global variables are initialized with 0 and since we are not changing value of y anywhere in the program, it will remain same. monanshi answered Dec 10, 2015 monanshi comment Share Follow See 1 comment 1 1 comment reply Ankit Raina 7 commented Sep 30, 2019 i edited by Ankit Raina 7 Oct 6, 2019 reply Follow flag For static case : 'y' should be 1 as it is call by reference method here. 0 0 replyShare Please log in or register to add a comment.
3 3 votes In static scoping value will be 6,And in Dynamic scoping value will be 2 srestha answered Dec 10, 2015 srestha comment Share Follow See all 3 Comments 3 3 Comments reply Pratik Gawali commented Dec 16, 2018 reply Follow flag Value of y is printed which must be 1 for static scoping and 2 for dynamic scoping (assuming pass by reference) 1 1 replyShare N Prasanna kumar commented Dec 24, 2018 reply Follow flag x value is not printed anywhere in the given program. Only y value is printed . 1 1 replyShare S_M commented Jul 16, 2020 reply Follow flag Can you explain in detail please? 0 0 replyShare Please log in or register to add a comment.
0 0 votes static=6 dynamic=2 mahak Sharma answered Sep 10, 2016 mahak Sharma comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes In static scoping: 1 In dynamic scoping: 2 if call by reference is used then in static scoping when the function B is called inside the function A the statement x= x+1 will change the global value of x = 5 6 but the main function is never using this global value of x it is printing the value of actual parameter y which is the formal parameter z in function A. and z = 1, so, 1 will be printed in the case of static scope. and when Dynamic scoping is used and the function B is called inside function A the statement x= x+1 will change the value of the variable x present in the calling function i.e. A, so X= 1 2 Pratham rathore answered Jan 5, 2021 Pratham rathore comment Share Follow 0 reply Please log in or register to add a comment.