Programming and data structure miscellaneous


Programming and data structure miscellaneous

Programming & Data Structure

Direction: The following program fragment is written in a progrmming language that allows global variable and does not allow nested declrations of functions.
   global int i = 100, j = 5;
   void P (x) {
    int i = 10;
    print (x + 10);
    i = 200;
    j = 20;
    print (x);
   }
   main () {P (i + j);}

  1. If the programme language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are









  1. View Hint View Answer Discuss in Forum

    In dynamic scoping, the local values are considered & variables are initialized at run time.
    Since x = i + j & in P (x)
    i = 200 &j = 20 x = 200 + 20 = 220
    & printing (x + 10)
    9. = i + j + 10 = 10 + 5 + 10 = 25
    Hence (b) is correct option

    Correct Option: B

    In dynamic scoping, the local values are considered & variables are initialized at run time.
    Since x = i + j & in P (x)
    i = 200 &j = 20 x = 200 + 20 = 220
    & printing (x + 10)
    9. = i + j + 10 = 10 + 5 + 10 = 25
    Hence (b) is correct option


  1. If the programming language uses static scoping and call by need parameter passing mechanism, the values printed by the above program are









  1. View Hint View Answer Discuss in Forum

    In static scoping the variables are initialized at compile time only
    So i = 100 &j = 5
    P (i + j) = P (100 + 5) = P(105)
    So x = 105
    x + 10 = 105 + 10 = 115
    So 115 & 105 will be printed.
    Hence (d) is correct option.

    Correct Option: D

    In static scoping the variables are initialized at compile time only
    So i = 100 &j = 5
    P (i + j) = P (100 + 5) = P(105)
    So x = 105
    x + 10 = 105 + 10 = 115
    So 115 & 105 will be printed.
    Hence (d) is correct option.



  1. Consider the following class definition in a hypothetical object oriented language that supports inheritance and uses dynamic binding. The language should not be assuemed to be either Java or C++, though the syntax is similar.
    Class P { Class Q subclass of P {
    void f (int i) { void f (int i) {
    print (i); print (2*i);

      }
    }
    Now, consider the following program fragment”
    Px = new Q()
    Qy = new Q();
    Pz = new Q();
    X.f(1); ((P)y). f(1); z.f(1);
    Here, ((P)y) denotes a type cast of y to P. The output produced by executing the above program fragment will be









  1. View Hint View Answer Discuss in Forum

    1. Px = newQ();
    2. Qy = newQ();
    3. Pz = newQ();
    4. x : f (1); print 2 # i = 2
    5. ((P) y) : f (1);
    6. z : f (1) print 2 # i = 2
    but line 5. will print 2 because typecast to parent class can't prevent over ridding. So function f(1) of class Q will be called not f (1) of class P.
    Hence (d) is correct option.

    Correct Option: D

    1. Px = newQ();
    2. Qy = newQ();
    3. Pz = newQ();
    4. x : f (1); print 2 # i = 2
    5. ((P) y) : f (1);
    6. z : f (1) print 2 # i = 2
    but line 5. will print 2 because typecast to parent class can't prevent over ridding. So function f(1) of class Q will be called not f (1) of class P.
    Hence (d) is correct option.


  1. Which of the following is not an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries?









  1. View Hint View Answer Discuss in Forum

    The advantages of shared dynamically linked libraries include.
    (a) smaller size of executable since less data
    (b) lesser overall page fault rate.
    (c) No need for re-linking if newer versions of libraries are there.
    But since compilation time doesn't include linking so a long linking time required during runtime in DLL ' s so slow startup.
    Hence (c) is correct option.

    Correct Option: C

    The advantages of shared dynamically linked libraries include.
    (a) smaller size of executable since less data
    (b) lesser overall page fault rate.
    (c) No need for re-linking if newer versions of libraries are there.
    But since compilation time doesn't include linking so a long linking time required during runtime in DLL ' s so slow startup.
    Hence (c) is correct option.



  1. Which of the following statements is false?









  1. View Hint View Answer Discuss in Forum

    (a) True for statically typed languages where each variable has fixed type. Similarly (d) is also correct.
    (b) True, in un-typed languages types of values are not defined.
    But option (c) is false, since in dynamically typed language variables have dynamically changing types but not that they have no type. Hence (c) is correct option.

    Correct Option: C

    (a) True for statically typed languages where each variable has fixed type. Similarly (d) is also correct.
    (b) True, in un-typed languages types of values are not defined.
    But option (c) is false, since in dynamically typed language variables have dynamically changing types but not that they have no type. Hence (c) is correct option.