Redirected
1,501 views
2 votes
2 votes

What is the output???

5 Answers

2 votes
2 votes

when static scoping is used :

x is global with value 10;

Part2(&x)


               another x is created with local scope and static : x=15;

               *b=*b *x; value of global x = 150;

                 Part1(&x) // this is calling to part1 by passing local x address

                                *a+=x++; // here += is RL assosiative so first x++ will be evaluated then +=   and this is static scoping so first we will search in local x then global x so no local x to part1 is there then go to global x and increment it, now global  x=151.

                               *a+= 150;

                               *a=15+150=165; local x=165;

                               print(165);

             //part2 print(local x = 165)

Part1(&x):// global x=151

                *a+=151; global x=152

                 *a=*a+151; 152+151=303 ; global x=303

                 print(303);

When Dynamic scoping is used:  https://courses.cs.washington.edu/courses/cse341/03wi/imperative/scoping.html

global x=10;

Part2(&x):

              another x is created with local scope and static : x=15;

              *b=*b *x; value of global x = 150;

               Part1(&x) // this is calling to part1 by passing local x address

                             *a+=x++; // this is dynamic scoping so first value it will search in local scope then in its caller function so at part2 it will get x=15;

                              *a+=15; now post increment x=16

                              *a=16+15=31;  local x=31

                              print(31);

               print(31)

Part1(&x):// global x=150

               *a+=150; here x will find x in global so x=151

               *a=151+150=301

               print(301);

 

 

with Static scoping :

165

165

303

with dynamic scoping :

31

31

301

0 votes
0 votes
In static scoping value is directed from main () .while in dynamic scoping value is called from local function
0 votes
0 votes

I m giving solution only using static scope,in which if there is any free variable then value will be taken by this free variable only from static area where all global variable and static variable are declared,.

Try to understand my solution ,let me know where u getting problem

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
tishhaagrawal asked Dec 16, 2023
354 views
Below is my approach to solving this question, can anyone please explain if I am doing it the right way?Let X = #free slotssince, m =7 and n = 3So, $4 \leqslant x\leqsla...
0 votes
0 votes
0 answers
3
Dadu asked Dec 7, 2023
212 views
Please solve I am unable to understand the solution given by made easy