C Program To Implement The Swapping Using Call By Reference Technique.This is the another C program to swapping data between two variable using call by reference method and call by value. In call by reference the addresses of actual arguments in the calling function are copied into formal arguments of the called functions.
This means that using these addresses we would have an access to the actual arguments and hence we would be able to manipulate them
ALGORITHM:-
step 1 : start
step 2 : Input two number
step 3 : Define an function with two pointer type variable
step 4 : Interchange the variable value using third variable
step 5 : Call that function using addresses of two variable
step 6 : Stop Execution
PROGRAM CODE:-
#include<stdio.h>
#include<stdio.h>
void swap( int *x, int *y )
{
int t ;
t = *x ;
*x = *y ;
*y = t ;
printf("value before swapping: ");
printf( "\nx = %d y = %d", *x,*y);
}
int main( )
{
int a = 10, b = 20 ;
swap ( &a, &b ) ;
printf("value after swapping: ");
printf ( "\na = %d b = %d", a, b ) ;
return 0;
getch();
}
OUTPUT:-
value before swapping
a = 10, b = 20
value after swapping
a = 20, b = 10
C program to swapping two variable data using call by refernce Implementing call by reference techinque Call by reference and Call by Value
ConversionConversion EmoticonEmoticon