Template is used for creating generic functions as well as data members
Templates allows us to write a class or functions without different parameters... Example:- If you want to write the function which can be called by passing int as well as float and return type is also generic means it returns int if you pass int to the function and returns float if you pass float to it then write it as..
template <class T> T fun_name(T a) { return a; }
above is the function template now you can call it as
int i=10,j; j=fun_name(i);
as well as
float f=10.23,g; g=fun_name(f);
it means fun_name() is generic its arguments are also generic as well as return type is also generic
template is used for generic functions. using templates we can pass any type of arguments to a function as well as we can receive any type of values from the function. tempaltes reduces the program length. only one function is enough for any kind of calling functions.