Actual And Formal Arguments
The arguments may be classified under two groups, actual and
formal arguments.
(a) Actual arguments An actual argument is a variable or
an expression contained in a function call that replaces the formal parameter
which is a part of the function declaration.
Sometimes, a
function may be called by a portion of a program with some parameters and these
parameters are known as the actual arguments.
For example,
#include <iostream.h>
void main ()
{
int x,y;
void output (int x, int y) ; /
/ function declaration
output (x,y) ; / / x and y are
the actual arguments
}
(b) Formal arguments Formal arguments are the parameters
presents in a function definition which may also be called as dummy arguments
or the parametric variables. When the function is invoked, the formal
parameters are replaced by the actual parameters.
For example,
#include <iostream.h>
void main ()
{
int x,y;
void output (int x, int y) ;
output (x,y) ;
}
void output (int a, int b) / / formal or dummy arguments
{
/ /body of the function
}
Formal arguments may
be declared by the same name or by different names in calling a portion of the
program or in a called function but the data types should be the same in both
blocks.
For example, the following function declaration is invalid.
#include <iostream.h>
void main ()
{
void funct (int x, int y, char s1,
char s2) ;
int x,y;
char s1, s2;
funct (x,y,s1,s2) ;
}
funct (char c1, char c2, int a, int b) /
/ data type mismatch
{
/ / body of a function
}
Thanks☺
ReplyDeleteThanks☺
ReplyDeleteThanks a lot
ReplyDelete