Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. Consider the following program :
      Program P2
       var n : int :
       procedure W (var x:int)
       begin
       x = x + 1;
        print x;
       end procedure D
       begin
         varn:int;
         n = 3;
         W (n);
      End
    begin       || begin P2
       n = 10;
       D;
      end
    If the language has dynamic scopping and parameters are passed by reference, what will be printed by the program?
    1. 10
    2. 11
    3. 3
    4. None of these
Correct Option: D

n = 10 given but not passed to D. In D, n = 3 &W(n) increments by 1. So n = n + 1 = 4.
Hence (d) is correct option.



Your comments will be displayed only after manual approval.