This is C program where user asks to interchange the two values with each other using Call by reference method. Declaring the required variable for functionality. Then after user declare void swap() function that which will give the reference to other class for interchange. After that user call the function that declare void swap() then using method to interchange the value of variables with the help of pointer concept to declare pointer type variables that are useful while using the call by reference method. In the end the result has to be display on the screen.
Problem statement:
This is C program that asks the user to interchange the value of two variables with use of call by reference Method.
- Declaring variables.
- Make function.
- Calls the function.
- Using Interchange method for value swapping.
- Display result on the screen.
Here is C source code for interchange value of two variables using Call by reference Method. The output of this program shown below.
#include<stdio.h>
void main()
{
int a=40;
int b=70;
void swap(int *x,int *y);
clrscr();
printf("a=%d,b=%d",a,b);
swap(&a,&b);
printf("\nAfter Swaping Result is :\na=%d b=%d ",a,b);
getch();
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}