0% found this document useful (0 votes)
30 views13 pages

Passing Parameter of Function

The document discusses different ways of passing parameters to functions in C programming. It defines formal and actual parameters and explains call by value, call by reference, and call by address. Call by value copies the value while the other two pass the address, allowing the parameter to be modified. Examples are provided to illustrate the different behavior.

Uploaded by

poojast2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views13 pages

Passing Parameter of Function

The document discusses different ways of passing parameters to functions in C programming. It defines formal and actual parameters and explains call by value, call by reference, and call by address. Call by value copies the value while the other two pass the address, allowing the parameter to be modified. Examples are provided to illustrate the different behavior.

Uploaded by

poojast2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

PASSING

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.

Parameters are specified after the function name inside


the parentheses. You can add as many parameters as
you want, just separate them with a comma:

SYNTAX:
Function name(parameter1,parameter2,parameter3)
TYPES OF PARAMETERS :
➢ FORMAL PARAMETER : The parameter received by a
function .

➢ ACTUAL PARAMETER : The parameter passed to 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)

2. PASS BY REFERENCE (CALL BY REFERENCE)

3. PASS BY ADDRESS
PASS BY VALUE (CALL BY VALUE):

Here values of actual parameter will be copied to formal


parameter and these two parameter store the value in
different location

Int x=10 , y=20; int fun (intx,inty)


fun(x,y) {
x=20;
y=10;
}
Output: x=10 , y=20
ADVANTAGES:
1. MAKES THE FUNCTIONS MORE SELF-CONTAINED

2. PROTECT THEM AGAINST ACCIDENTAL CHANGES

DISADVANTAGES:
1. IT DOES NOT ALLOW INFORMATION TO BE TRANFERED BASE TO THE

CALLING FUNCTION IN ARGUMENTS

2. PASS BY VALUE IS REQUIRED TO ONE WAY TRANSFER OF INFORMATION

FROM CALLING FUNCTION TO CALLED FUNCTION


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=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

You might also like