have a look at the complex procedure prgm and just tell me the output
wht it will be. i have come up with a explanation.
program outer(input, output);
var n, k: integer;
procedure p(procedure f; var j: integer);
label 1;
var i: integer;
procedure q;
label 2;
begin { q }
n := n+1; if n=4 then q;
n := n+1; if n=7 then 2: j := j+1;
i := i+1;
end; { q }
begin { p }
i := 0;
n := n+1; if n=2 then p(q,i) else j := j+1;
if n=3 then 1:f;
i := i+1;
writeln('i=',i:1);
end; { p }
procedure empty; begin end;
begin { outer }
n := 1; k := 0;
p(empty, k);
writeln('k=', k:1);
end. { outer }
i worked out this complex procedure and found the output to be the
following,
(If we evaluate step by step we will end up like this)
program outer:
***************
n=1, k=0
p(empty,k) fucntion p is called. so, f=empty, j=0;
program p(1):
**************
i=0, then n=2. condition satisfied so p(q,i).
fucntion p is again called. f=q,
j=i;(call by reference)
program p(2):
**************
i=0, then n=3 and j=1
condition satisfied. f which is q is called.
program q(1):
**************
n=4, program q is called again.
program q:
***********
n=5, then it becomes n=6.
i=2. q ends.
control to q(1).
program q(1) contd....
***********************
n=7 j=3, i=4 and program ends.
program p(2) contd....
***********************
i=5 and output is i=5.
program p(2) ends.
program p(1) contd....
***********************
i=6 and output is i=6.
program p(1) ends.
program outer contd...
***********************
output is k=0.
program outer ends.
thus the output of the program will be i=5, i=6 and k=0. wht do u
think it shld be??
puzzled,
Knack.