• edited by
4,278 views
8 8 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?

3 Answers

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

Related questions

51 51 votes
8 answers 8 answers
18.0k
18.0k views
Kathleen asked Sep 14, 2014
17,964 views
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it, counting repetiti...
14 14 votes
2 answers 2 answers
11.5k
11.5k views
Kathleen asked Sep 15, 2014
11,519 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...
3 3 votes
1 answers 1 answer
2.3k
2.3k views
Kathleen asked Oct 9, 2014
2,256 views
Consider the following program in pseudo-Pascal syntax. What is printed by the program if parameter $a$ in procedure $\text{test1}$ is passed ascall-by-reference paramete...
5 5 votes
1 answers 1 answer
2.8k
2.8k views
Kathleen asked Sep 29, 2014
2,778 views
Consider the following program in Pseudo-Pascal syntax.program what: var z: integer procedure recur(x): begin if x <= 40 then begin x:x+z recur(x); z:=x+10 end end(*recur...