The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+5 votes
1.1k views

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?
asked in Programming by Veteran (52.1k points)
edited by | 1.1k views
0
can someone explain the part b how does it works.

2 Answers

+8 votes
Best answer
  A) Call By Value : 12 7 10 5  B) Call By Reference : 14 14 10 10
answered by Active (3k points)
edited by
+6
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.
+1 vote

COLL BY VALUE; 12,7,10,5

answered by Boss (34.2k points)
edited by

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,811 questions
54,533 answers
188,417 comments
75,579 users