Skip to content

Instantly share code, notes, and snippets.

@nalin-adh
Created November 10, 2015 16:55
Show Gist options
  • Save nalin-adh/27cb9e971d0d07b2aa7b to your computer and use it in GitHub Desktop.
Save nalin-adh/27cb9e971d0d07b2aa7b to your computer and use it in GitHub Desktop.
A C++ program that swaps data using reference variable.
#include<iostream>
#include<conio.h>
using namespace std;
void swap(int &,int &);
int main()
{
int a,b;
cout<<"Enter first number : ";cin>>a;
cout<<"Enter second number : ";cin>>b;
swap(a,b);
cout<<"After Swap !!!";
cout<<"\nFirst number is "<<a;
cout<<"\nSecond number is "<<b;
getch();
return(0);
}
void swap(int &x,int &y)
{
int z=x;
x=y;
y=z;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment