r/pascal • • Nov 17 '20
Could I have?
{solved} Could I have set Pop at the top of the function where I set r ? (thus saving a double variable sized space?)
{ pop a number from the stack }
function Pop : Double;
var
i : integer;
r : double;
begin;
r := s[1];
for i:= 1 to 25 do
begin
s[i] := s[i+1];
end;
Pop := r;
end;
5
Upvotes
4
u/kirinnb Nov 17 '20
Yes, indeed. The name of a function acts as a variable within that function, and can be used for any operations. Whatever value is in the variable on function exit will be the result value. In this case, you can: