in Programming edited by
1,862 views
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 edited by
1.9k views

1 comment

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

Subscribe to GO Classes for GATE CSE 2022

2 Answers

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
1 vote

COLL BY VALUE; 12,7,10,5

edited by

Related questions

Ask
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