0% found this document useful (0 votes)
24 views2 pages

Pointers As Function Argmnts

The document discusses how pointers can be used as function arguments in C by passing the address of variables. When a function is called by reference, any changes made to the reference variable will affect the original variable. The steps to use call by reference are to declare pointer parameters in the function prototype and definition, then pass the addresses of variables as arguments when calling the function.

Uploaded by

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

Pointers As Function Argmnts

The document discusses how pointers can be used as function arguments in C by passing the address of variables. When a function is called by reference, any changes made to the reference variable will affect the original variable. The steps to use call by reference are to declare pointer parameters in the function prototype and definition, then pass the addresses of variables as arguments when calling the function.

Uploaded by

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

Pointers as function arguments:

Pointer in function parameter list is used to hold address of argument passed during function call , This is
also known as call by reference. When a function is called by reference
any change made to the reference variable will effect the original variable.

In this method, by using formal arguments in the called function ,we can make changes in actual
arguments of calling Function. This mechanism is known as “Call By Address” (or) “Call By
Reference”.

To make use of call by reference the steps are : -

Step 1 In Prototype declare the parameter as a pointer with *

Example: void swap(int *x , int *y) ;

Step 2. In Function header of function definition also declare the parameter as pointer with *.

In the body of the function access it through dereferencing operator *.

void swap(int *x, int *y)

int temp;

temp=*x;

*x=*y;

*y=temp;

Step 3. In Function call pass address of the parameter as parameter.

int main()
{
---
---
swap(&p,&q);

Example program on Pointers as function arguments

#include<stdio.h>
#include<conio.h>
void swap(int *, int *);
void main()
{
int a,b;
a=10;
b=20;
swap(&a,&b);
printf(“value of a=%d and b=%d”,a,b);
getch();
}
void swap(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}

You might also like