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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

1 comments: