Tuesday 3 August 2010

Function and Procedure

There are two kind of subroutine in Pascal : Function and Procedure. The difference between these subroutines is in return value. Function gives a return value, but procedure doesn’t. The structure of function and procedure are the same :

Here is the example of procedure and function :

program FunctionAndProcedure;
{$APPTYPE CONSOLE}
uses
   SysUtils;

procedure Add1(x, y : integer);
 var
  z : integer;
begin
  z := x + y;
  writeln(x,' + ',y,' = ',z,' (using procedure)');
  readln;
end;

function Add2(x, y : integer) : integer;
begin
  Add2 := x + y;
end;

begin
  Add1(25,10);
  writeln('25 + 40 = ',Add2(25,40),' (using function)');
  readln;
end.

You can download the complete code here.

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.