//swap 2 number using pointer
#include<iostream>
using namespace std;
int main()
{
int c,a,b,*p1,*p2;
cout<<"enter two no.\n";
cin>>a>>b;
p1=&a;
p2=&b;
c=*p1;
*p1=*p2;
*p2=c;
cout<<"swap is.";
cout<<*p1<<*p2;
}
#include<iostream>
using namespace std;
int main()
{
int c,a,b,*p1,*p2;
cout<<"enter two no.\n";
cin>>a>>b;
p1=&a;
p2=&b;
c=*p1;
*p1=*p2;
*p2=c;
cout<<"swap is.";
cout<<*p1<<*p2;
}
No comments:
Post a Comment