• edited by
14,451 views
0 0 votes
int x=5;
void f()
{
    x = x+50;
}

void g(h())
{
    int x=10;
    h();
    print(x);
}

void main()
{
    g(f());
    print(x);
}

1) what is output if code uses deep binding?

2)what is the output if code uses shallow binding?

1 Answer

Best answer
6 6 votes

Deep/shallow binding makes sense only when a procedure can be passed as an argument to a function.

  • Deep binding binds the environment at the time a procedure is passed as an argument.
  • Shallow binding binds the environment at the time a procedure is actually called. 

1. Deep binding.

f() gets the environment of main, since f() is passed as an argument in main. At the time of passing, x in main (the global x) is 5. So, f changes the global x to 55, and g prints the local x as 10.

2. Shallow binding.

f() gets the environment of g at the time it is called. So, f changes the x in g to 10+50 = 60, and g prints the value 60.

• selected by
Position:
Show:

Related questions

2 2 votes
2 2 answers
1.4k
1.4k views
ykrishnay asked May 23, 2022
1,405 views
// C/C++ program to demonstrate return value// of printf()#include <stdio.h>int main(){ long int n = 123456789; printf("While printing "); printf(", the value re...
0 0 votes
1 answers 1 answer
1.4k
1.4k views
Priya Brata asked May 28, 2016
1,365 views
Both * and ++ have equal precedence with right to left associativity. So *s++ will be evaluated as *(s++) it means first increase the location of s to next location the...