Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pascal

What are procedures in Pascal?

Sheza Munir

Procedures in Pascal are sub-programs that return a group of results. They are defined using the procedure keyword.

Definition

The following snippet shows how procedures are generally defined:

procedure name(argument(s): type1, argument(s): type2, ... );
   {local declarations}
begin
   {procedure body}
end;

Arguments

Arguments create a link between the calling program and the procedure. They are also called formal parameters.

Local declarations

These refer to the declarations for variables, constants, functions, procedures, and labels whose scope is limited to the procedure itself.

Procedure body

This is where the procedure defines its implementations and calculations. The procedure body is enclosed between the keywords begin and end.

Code

The following code shows the implementation of a procedure in Pascal:

program Example;
var 
   a, b, max: integer;

procedure findBigger(x, y: integer; var m: integer); 
{ Finds the maximum of the 2 values }
begin
   if x > y then
      m := x
   else
      m := y;
end; { end of procedure findBigger } 

begin 
    a = 2
    b = 3
    findBigger(a, b, max); {procedure call}

    writeln(' The larger number is: ', min); {prints 3}

RELATED TAGS

pascal

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring