Passing Parameter of Function
Passing Parameter of Function
PARAMETER OF
FUNCTION
CONTENTS:
❑PARAMETER DEFINATION.
❑TYPES OF PARAMETETR.
❑TYPES OF CALLING FUNCTION.
❑PASS BY VALUE.
❑PASS BY ADDRESS.
PARAMETERS DEFINATION:
Information can be passed to functions as a parameter.
Parameters act as variables inside the function.
SYNTAX:
Function name(parameter1,parameter2,parameter3)
TYPES OF PARAMETERS :
➢ FORMAL PARAMETER : The parameter received by a
function .
Example:
add(m,n) int add (int a, intb )
{
return(a+b);
}
TYPES OF CALLING FUNCTION:
1. PASS BY VALUE (CALL BY VALUE)
3. PASS BY ADDRESS
PASS BY VALUE (CALL BY VALUE):
DISADVANTAGES:
1. IT DOES NOT ALLOW INFORMATION TO BE TRANFERED BASE TO THE
a=10
b=20
PASS BY ADRESS:
❑In pass by address, when a function is called the
address of actual parameters are sent , the addresses
of actual parameters are sent, the addresses of actual
parameters are copied integer formal parameters.
❑This way of changing the actual parameters
indirectly using the addresses of actual parameters
is called pass by address
❑So both actual and formal parameters points to the
same memory location, so changes in formal
parameters reflects the changes in actual parameters.
EXAMPLE:
#include<stdio.h>
Void exchange (int*m, int*n)
{
int temp;
temp=*m;
*m=*n;
*n=temp;
}
void main()
{
int a, b;
a=10, b=20;
exchange(&a,&b);
printf (“a=%d & b=%d” ,a, b);
getch();
}
OUTPUT:
a=20
b=10
THANK YOU