C++ program to swap values of two variables using pass by reference method

C++ program to swap values of two variables using pass by reference method

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int a,b;
void swap(int &,int &);
cout<<“Enter two values:”;
cin>>a>>b;

cout<<“nBefor swapping:na=”<<a<<“tb=”<<b;
swap(a,b);
cout<<“nnAfter swapping:na=”<<a<<“tb=”<<b;
getch();
}

void swap(int & x,int & y)
{
int temp;
temp=x;
x=y;
y=temp;
}

2 thoughts on “C++ program to swap values of two variables using pass by reference method

  1. Murad Ali

    it is not compiling
    compiler is generating error that “cin” and “cout” are not declared (first use this function)

    Reply
  2. Zee

    Great tutorial, love how it’s well explained. Altho error coming on output, so please do update the article. Thanks 🙂

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *