Pointers As Function Argmnts
Pointers As Function Argmnts
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”.
Step 2. In Function header of function definition also declare the parameter as pointer with *.
int temp;
temp=*x;
*x=*y;
*y=temp;
int main()
{
---
---
swap(&p,&q);
#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;
}