What are actual and formal parameters?

Parameters are two types:
1. Formal Parameters: 
  • The variables which are used to specify or declare types of data to passed to the procedures are formal parameters. In other words, formal parameters are those variables that is used inside parenthesis immediately after Procedure name in the declaration part. On the other hand, a formal parameter is always a variable.
  • It is not mandatory to keep the formal parameters with all the procedures, at that time the calling code does not have to pass the value for it. The name of each parameter servers as a local variable in the procedure.

2. Actual or Real Parameters: 
  • Actual parameters (or real parameters) are the arguments which are used to pass real value or data to the procedures. Actual parameters may be variables or constant values. 
  • The data type of arguments and the formal parameters should match according to the order they are passed to the procedure.
Example 1:
DECLARE SUB add (m, n) [here 'm' and 'n' are formal parameters)]
x=5
y=6
CALL add (x, y)
END

SUB add (m, n)
a=m+n
PRINT a
END SUB

Here, in the example, m and n are formal parameters and  x and y are actual parameters.


Example 2:
DECLARE SUB interest (x,y,z) [Here, x, y, z are formal parameters]
CLS
INPUT "Enter principal amount"; p
INPUT "Enter time ratio"; t
INPUT "Enter rate"; r
CALL interest (p, t, r) [Here p, t, r are actual parameters]
END

SUB interest (x, y, z)
i = (x * y * z) / 100
PRINT "Simple interest = "; i
END SUB

Share :

Twitter
Back To Top

facebook main

counter

Powered by Blogger.