skip to main | skip to sidebar

Sunday, April 12, 2009

FUNCTION TEMPLATES PROGRAM

#include
#include
templatevoid swaparg(x &a,x &b)
{
x temp;
temp=a;
a=b;
b=temp;
}
void main()
{
int i=10,j=20;
double x=10.1,y=23.3;
char a='y',b='z';
clrscr();
cout<<"\noriginal i and j: "<< i<<" ,"<< j;
cout<<"\noriginal x and y: "<< x<<" ,"<< y;
cout<<"\noriginal a and b: "<< a<<" ,"<< b;
swaparg(i,j);
swaparg(x,y);
swaparg(a,b);
cout<<"\n\nswapped i and j: "<< i<<", "<< j;
cout<<"\nswapped x and y: "<< x<<" ,"<< y;
cout<<"\nswapped a and b: "<< a<<", "<< b;
getch();
}


Output will be:


Original i and j : 10, 20
Original x and y: 10.1, 23.3
Original a and b: y, z

Swapped i and j : 20, 10
Swapped x and y: 23.3, 10.1
Swapped a and b: z, y

No comments:

Post a Comment

[フレーム]

Subscribe to: Post Comments (Atom)

AltStyle によって変換されたページ (->オリジナル) /