generic programming

Generic programming is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.
 
In very simple terms Generic programming is a type of programming in which we program without considering type of the functions and classes. This allows a function or class to work on many different data types without being rewritten for each one. Consider the following example for adding two integers:

for integers

#include <iostream>
using namespace std;

void gettingSum(int a, int b)
{
	cout << a + b; // will output sum as 5
}

int main()
{
	gettingSum(2, 3);
	return 0;
}

now the same program for float values

#include <iostream>
using namespace std;

void gettingSum(float a, float b)
{
	cout << a + b; // will output sum as 5.9
}

int main()
{
	gettingSum(2.3, 3.6);
	return 0;
}

Both of the above program has minor change from int values to the int values. But in order to evaluate the values of different types we have to write the whole program for some minor changes. This problem is solved by templates. Templates will be explained in next tutorial.