Function Overloading with an Example in C++ – to find the sum

In this tutorial, we will Learn:

Write a C++ program to define three overloaded functions to find the sum of two integers, sum of two floating-point numbers, and the sum of three integers.

Solution:

Video Tutorial:

Function overloading means, two or more functions have the same names but different argument lists.

The arguments may differ in the type of arguments or number of arguments, or both.

However, the return types of overloaded methods can be the same or different is called function overloading.

Function overloading conceptshelps us to use the same function names multiple time in the same program.

Following program demonstrates the overloaded function to find the sum of two integers, sum of two floating-point numbers, and the sum of three integers.

``` #include<iostream>
using namespace std;

int sum(int x, int y)
{
return x+y;
}
double sum(double x, double y)

{
return x+y;
}

int sum (int x, int y, int z)
{
return x+y+z;
}

int main()
{
cout <<"The Sum of two integers: "<<sum(10, 20)<<endl;
cout <<"The Sum of two floats: "<<sum(10.5, 20.7)<<endl;
cout <<"The Sum of three integers: "<<sum(10, 20, 30)<<endl;
}```

OUTPUT: