in Programming in C edited by
2,993 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?
in Programming in C edited by
3.0k views

1 comment

can someone explain the part b how does it works.
0
0

2 Answers

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

1 comment

Call by reference result should be: 14 14 10 10, because procedure P has its own local x which gets changed on calling it, there is no assignment of y therefore, it will not change the value of global x.
6
6
2 votes
2 votes

COLL BY VALUE; 12,7,10,5

edited by

Related questions