- 1
Write a program that swap two number using pointers.???
please answer immediately
5 Respuestas
+ 6
template<typename T>
void swap( T*p1, T* p2)
{
T* temp = new T;
temp = p1;
p1 = p2; p2= temp;
}
int main()
{
int a,b;
cin>>a>>b;
swap(&a, &b);
cout<<a<<" "<<b<<endl;
}
Edit : Try this if the above didn't work :
#include<iostream>
using namespace std;
template<typename T>
void swap(T* p1, T* p2)
{
T* temp = new T;
*temp = *p1;
*p1 = *p2; *p2 = *temp;
}
int main()
{
int a,b;
cin>>a>>b;
swap(&a, &b);
cout<<a<<" "<<b<<endl;
}
+ 3
Just excluding the headers...
+ 3
😀
+ 1
starting se hai??
0
p1=p2;p2=temp; wrong bta raha hai
so please help me