TEMPLATES

SOURCE CODE:
#include<iostream.h>
#include<conio.h>
template<class T>
void swap(T &x,T &y)
{
 T temp = x;
 x = y;
 y = temp;
}
void fun(int m,int n, float a,float b)
{
 cout<<"m and n before swap : "<<m<<" "<<n<<"\n";
 swap(m,n);
 cout<<"m and n after swap : "<<m<<" "<<n<<"\n";
 cout<<"a and b before swap : "<<a<<" "<<b<<"\n";
 swap(a,b);
 cout<<"a and b after swap : "<<a<<" "<<b<<"\n";
}
void main()
{
 clrscr();
 fun(100,200,11.22,33.44);
 getch();
}

OUTPUT:

m  and  n  before swap :  100      200
m  and  n  after swap :    200     100
a  and  b  before swap :   11.22     33.439999       
a  and  b  after swap :   33.439999    11.22  
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: