edited by
481 views
0 votes
0 votes

Q.   

int k;
fun(int i)
{   
  k = i + 3;
  printf(k);
}
gun( int i)
{
  int k = 4;
  k = i+4;
  fun(k);
  printf(k);
}
main(){
  k=2 ;
  gun(k);
  printf(k);
}



my result

static scoping - 9,6,2   ( here last print statement i have doubt ..it will print 2 or 9)

dynamic scoping- 9,9,2

edited by

2 Answers

1 votes
1 votes
In Static Scoping, if a variable is not defined in the Local space, it is looked in Globle Space.

In Dynamic Scoping,  if a variable is not found in the Local space , it is looked in the place, where it recursive called.

In Static

gun() have local variable 'k' and pass updated value "6"  ............

In fun(), there are no loval variable 'k' so in static dynamic it use GLOBLE variable and update then with  k = i + 3   = 6+3 = 9

So in main() , print() print 9  .

Hope you will understand.

Related questions

2 votes
2 votes
4 answers
2
admin asked Mar 31, 2020
1,032 views
How will you free the allocated memory?remove(var-name)free(var-name)delete(var-name)dalloc(var-name)