Write a progarm to swap the values of two variables using pointers in C++?



 #include<iostream.h>
   #include<conio.h>
  int swap(int*,int*);      
  void main()
{
int num1,num2;
clrscr();
cout<<"\nEnter first number:";
cin>>num1;
cout<<"\nEnter second number:";
cin>>num2;
swap(&num1,&num2); 
cout<<"\n\n After swapping numbers are:";
cout<<"NUM1= "<<num1<<endl<<"NUM2= "<<num2;
getch();
}
 int swap(int *a,int *b)   
{
  int temp=*a;
  *a=*b;
  *b=temp;
    }     




OUTPUT:-

Enter first number: 4
Enter second number: 5
After swapping numbers are:
NUM1= 5
NUM2= 4
 

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart