edited by
2,980 views
6 votes
6 votes

Consider the following program  is  pseudo-Pascal syntax

program main;
    var x: integer;  
    procedure Q (z: integer);
    begin     
        z := z+x; 
        writeln(z); 
    end; 
    procedure P (y: integer);
    var x: integer;
    begin     
        x := y+2;       
        Q(x);     
        writeln(x); 
    end  
begin  
    x := 5; 
    P(x); 
    Q(x); 
    writeln(x);
end

What is the output of the program when

  1. the parameter passing mechanism is call-by-value and the scope rule is static scoping?  
  2. the parameter passing mechanism is call-by-reference and the scope rule is dynamic scoping?
edited by

2 Answers

Best answer
9 votes
9 votes
  A) Call By Value : 12 7 10 5  B) Call By Reference : 14 14 10 10
edited by

Related questions

13 votes
13 votes
2 answers
1
Kathleen asked Sep 15, 2014
8,178 views
The results returned by function under value-result and reference parameter passing conventionsDo not differDiffer in the presence of loopsDiffer in all casesMay differ i...