in Programming in C
575 views
1 vote
1 vote
what will be the output of the code please elaborate the scopes ?

#include<stdio.h>
int a=10,b=20;
C(){  a=23;
      printf("%d %d\n",a,b);
      D();
      a=6,b=7;
   }
D(){  b=44;
     E();
     printf("%d %d\n",a,b);

   }
E(){
     printf("%d %d\n",a,b);
      a=1,b=2;
    }
int main()
{
    int a=5,b=6;
    C();
    a=2,b=3;
    E();
    printf("%d %d\n",a,b);
    
    return 0;
}
in Programming in C
575 views

4 Comments

but how can the first line be 23,20 it would rather be 23, 6 because as per kiran sir's lecture in dynamic scoping if you dont get a variable while executing a block the back track the sequence of execution  untill you find the value so that value of b would 6 instead of 20

0
0
in dynamic scoping the output will be

23,6

23,44

1,2

2,3

1,2
2
2

hitendra singh your output using dynamic scope is correct 

0
0

Please log in or register to answer this question.