Tuesday, 20 March 2018

Call by Pointer in C++

//call by pointer
#include<iostream.h>
#include<conio.h>
void swap(int *x,int *y);
void main()
{
 clrscr();
  int a,b;
  cout<<"Enter 2 values\n";
  cin>>a>>b;
  cout<<"\n\tBefore Swapping\n";
  cout<<"\n1st value="<<a<<"\t"<<"2nd value="<<b<<endl;
  swap(&a,&b);
  cout<<"\n\tAfter Swapping\n";
  cout<<"\n1st value="<<a<<"\t"<<"2nd value="<<b<<endl;
 getch();
}
void swap(int *x,int *y)
{
 int temp;
 temp=*x;
 *x=*y;
 *y=temp;
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.