.
Home About-us Privacy Policy Contact-us Services

Thursday, October 8, 2015

C++ program to call by reference

ad+1

Program -



#include<iostream.h>
#include<conio.h>
 void main()
{
clrscr();
int x,y,*p1,*p2;
void exchange(int,int);
cout<<"\n enter the value of x and y:";
cin>>x>>y;
p1=&x;
p2=&y;
cout<<"\n before exchange x="<<x<<"and y="<<y<<endl;
exchange(p1,p2);
cout<<"\n after the exchange x="<<*p1<<"and y="<<*p2;
getche();
}
void exchange(int*p3,int*p4)
{
int temp1;
temp1=*p3;
*p3=*p4;
*p4=temp1;
return;
}

Output - 
enter the value of x and y: 5    10
before exchange x=5and y=10
after exchange x=10 and y =5



 

0 comments:

Post a Comment

Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates