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.

6 comments:

  1. berkunjung ke tempat kawan untuk mencari ilmu yang tercecer

    moga sukses selalu kawan

    ReplyDelete
  2. dari t4 Pakde sulas di ajak mampir kesini ..
    ikut menyimak dan belajar sobb

    ReplyDelete
  3. Refreshing.. dulu pernah belajar tapi lupa lagi sob.
    TFS

    ReplyDelete
  4. penulisan fungsinya di atas pakai bahasa apa ya??

    ReplyDelete
  5. APTIMASTERS is basically an online aptitude site which provides the help for the students to make their aptitude skills more enhanced so that they can overcome the entrance examinations for CAT,MAT,UPSC ,Placement Exams etc .

    ReplyDelete
  6. s The best and a lot of secret drop-shipping suppliers in the world which will provide your products globally available for you directly to your customers doors. Also get the best drop-shipping manufacturer on your organization.

    ReplyDelete

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.