1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

dynamic scoping

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

  1. dano

    dano New Member

    Joined:
    Jun 21, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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