- 1

Write a program that swap two number using pointers.???

please answer immediately

27th Oct 2017, 7:18 AM
Rajesh Prajapati
Rajesh Prajapati - avatar
5 ответов
+ 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; }
27th Oct 2017, 7:43 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
Just excluding the headers...
27th Oct 2017, 7:53 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
😀
28th Oct 2017, 11:41 AM
jay
jay - avatar
+ 1
starting se hai??
27th Oct 2017, 7:49 AM
Rajesh Prajapati
Rajesh Prajapati - avatar
0
p1=p2;p2=temp; wrong bta raha hai so please help me
29th Oct 2017, 4:56 AM
Rajesh Prajapati
Rajesh Prajapati - avatar