2,718 views
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;

4 Answers

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.
3 3 votes

In static scoping value will be 6,And in Dynamic scoping value will be 2

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

Position:
Show:

Related questions

1 1 vote
1 1 answer
1.1k
1.1k views
sushmitha asked Sep 10, 2018
1,067 views
can anyone explain by using static and dynamic programing ? what will be output for static and dynamic? #include<stdio.h>int x=10;void part1(int *a){*a+=x++;printf("%d"...
0 0 votes
0 0 answers
1.6k
1.6k views
saumya mishra asked Dec 16, 2017
1,639 views
Can anyone please explain what is the answer to this question by static and dynamic scoping?
15 15 votes
1 answers 1 answer
6.4k
6.4k views
firki lama asked Jan 9, 2017
6,357 views
int a=0,b=0; int main(void) { int a=3; printf("%d%d",a,b); c(); printf("%d%d",a,b); return 0; } void c() { printf("%d%d",a,b); a=4,b=5; printf("%d%d",a,b); d(); printf("%...
7 7 votes
3 answers 3 answers
10.1k
10.1k views