Write a program to explain function overloading with the different number of arguments Function Overloading:
C++ enables two or more functions with the same name but with different types of arguments or with the different number of arguments. This capability to overload a function is called function overloading.
Program Code:
#include<iostream>
using namespace std;
int sum(int, int);
int sum(int, int, int)
void main()
{
int x=5;
int y=10;
int z=20;
int a=0,b=0;
a=sum(x,y);
b=sum(x,y,z);
cout<<"Sum of two integers = "<<a<<endl;
cout<<"Sum of three integers = "<<b<<endl;
}
int sum(int x,int y)
{
return(x+y);
}
int sum(int x,int y,int z)
{
return(x+y+z);
}
Output:
Sum of two integers = 15
Sum of three integers = 35
Thanks
Mukesh Rajput
Very nice
ReplyDelete