Return values through a function's parameter

edited April 2017 in Questions about Code

In Pascal, i heard about something like this:

program abc;
var x,y:integer;
procedure something(a,b:integer);
var c:integer;
begin
  c:=a;
  a:=b;
  b:=a
end;
begin
  a:=3;
  b:=5;
  {now a=3, b=5}
  swap(a,b);
  {now a=3, b=5}
end.

but if you were to add "var" before the parameters:

program abc;
var x,y:integer;
procedure something(var a,b:integer);
var c:integer;
begin
  c:=a;
  a:=b;
  b:=a
end;
begin
  a:=3;
  b:=5;
  {now a=3, b=5}
  swap(a,b);
  {now a=5, b=3}
end.

I wonder how can i achieve the same result? I also wonder what this problem is called.

Thanks in advanced for helping me.

Answers

Sign In or Register to comment.