1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

dynamic scoping

Discussion in 'C' started by dano, Jun 22, 2009.

  1. dano

    dano New Member

    Can someone help me understand dynamic scoping with this example?
    Code:
    void fun1(void);      /*prototype*/
    void fun2(void);     /*prototype*/
    void fun3(void);     /*prototype*/
    
    void main () {
        a, b, c;
        ...
    }
    void fun1(void) {
        int b, c, d;
        ...
    }
    void fun2(void) {
       int c, d, e;
       ...
    }
    void fun3(void) {
       int d, e, f;
       ...
    }
    
    Given the following calling sequence and assuming that dynamic scoping is used, what variales are visible during execution of the las function called? include with each visible variale the name of the function in which it was defined.

    a. main calls fun1, fun1 calls fun2; fun2 calls fun3
    b. main calls fun1; fun1 calls fun3
    c. main calls fun2; fun2 calls fun3; fun3 calls fun1
    d. main calls fun3; fun3 calls fun1
    e. main calls fun1; fun1 calls fun3; fun3 calls fun2
    f. main calls fun3; fun3 calls fun2; fun2 calls fun1

    Thank you in advance
     
    Last edited by a moderator: Jun 23, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Seems a trick question to me because there is an obvious answer and you might think why are they asking if it's that obvious, but what do you think the answer is dano, and why?
     

Share This Page