Tuesday 4 June 2019

What is difference between function overloading and template? tccicomputercoaching.com

Both function overloading and templates are examples of polymorphism .

Function overloading is used when multiple functions do similar operations; templates are used when multiple functions do identical operations.

Templates provide an advantage when you want to perform the same action on types that can be different.



Function Overloading works on different type’s no. of arguments.

Syntax:

1. template:
T sum(T a, T b)
{ T c;
c=a+b;
return c;
}

2. Function Overloading:


void sum(int a, int b)
{
ans =a+b;
}
void sum(int a , int b, int c)
{
ans=a+b+c;
}

To learn more concepts of Programming Languages at TCCI.

Visit us @ http://tccicomputercoaching.com/

Get Admission at TCCI.

Call us @ 9825618292

No comments:

Post a Comment