Templates

I want to know about Templates and Templates Program .
Please send me with the Syntax for Templates.
senexpertAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arikkaCommented:
0
sureshkumarCommented:
when ever there several functions with same body but different parameters then we can use templates by writing single function with general datatype for the parameters.I think now you got what is template.And one more thing is templates must write before main function.

# include<iostream.h>

template <class t>
void swap(t&x,t&y)
{
t temp;
temp=x;
x=y;
y=temp;
}

int main()
{
    int x,y;
     cout<<"enter the values of x,y";
     cin>>x>>y;

     swap(x,y);
     cout<<"the swaped value"<<x<<y;
return 0;
}
     
further queries
suresh kumar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
senexpertAuthor Commented:
Thank U For the Answer
0
sureshkumarCommented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.