[comp.lang.pascal] info-pascal

jdangel@lynx.northeastern.edu (08/24/89)

>   The following code produces 25 as output in Turbo Pascal 4.0.  Can
>anyone explain what is going on?
> 
>  var y:integer;
>
>  Function one(var x:integer):integer;
>  begin
>   x:=x+1;
>   one:=x;
>  end;
> begin
>  y:=4;
>  writeln(output,y*one(y));
> end.
>   
>   Edwin J. Kay
>   CSEE
>   Lehigh University
 
Aha!  In the main program the first portion of the writeln to be
evaluated is in fact the one(y) call because this requires one more
level of calling.
   
  The declaration you have is :
   Function one( var x: integer):integer;

  When you execute x:= x+1 , you are actually incrementing the value of
y in your main program.  So upon returning, the value that is printed is
5 * 5, not 4 * 5...

 Hope this helps..

  Jeff Dangel

internet::jdangel@lynx.northeastern.edu
prodigy::gkrf61a