83.5k views
4 votes
Explain by details function overloading in C++

User Ferenc T
by
5.7k points

1 Answer

3 votes

Answer:

Function overloading is the feature in C++ where two functions can have same name but having different arguments.Function overloading is used to implement polymorphism means existing in more than one form or to be specific run time polymorphism. Do not confuse it with function overriding both are different.

For example:-

#include<iostream>

using namespace std;

int sum1(int arg)

{

return arg+10;

}

int sum1(int arg1 ,int arg2)

{

return arg1+arg2;

}

int main()

{

int a=sum1(10);

int b=sum1(10,20);

cout<<a<<" "<<b;

return 0;

}

Output:-

20 30

The output is different according to the input.

User Hanane
by
5.1k points