IMPLEMENTATION OF CALL BY ADDRESS
AIM:
- To write a C++ program and to implement the concept of Call by Address
1. Start the program
2. Include suitable header file
3. Declare a function swap with two pointes variables arguments
4. Declare and initialize the value as two variable in main()
5. Print the value of two variable before swapping
6. Call the swap function by passing address of the two variable as arguments
7. Print the value of two variable after swapping
8. Stop the program
CODING:
#include<iostream.h>
#include<conio.h>
void swap(int *x,int *y);
int main()
{
clrscr();
int i,j;
i=10;
j=20;
cout<<"\n the value of i before swapping is:"<<i;
cout<<"\n the value of i before swapping is:"<<j;
swap (&i,&j);
cout<<"\n the value of i after swapping is:"<<i;
cout<<"\n the value of i after swapping is:"<<j;
getch();
return(0);
}
void swap(int *x,int*y)
{
int temp=*x;
*x=*y;
*y=temp;
}
OUTPUT:
The value of i before swapping is: 20
The value of j before swapping is: 10
The value of i after swapping is: 10
The value of j after swapping is: 20
RESULT:
- Thus to write a c++ program and to implement the concept of Call by Address was successfully completed.
0 comments:
Post a Comment