Simple example of Function Overloading in C++:
Program Code:
#include <iostream>
using namespace std;
int sum (int x, int y)
{
cout << x+y;
}
int sum(int x, int y, int z)
{
cout << x+y+z;
}
int main()
{
sum (10,20); // sum() with 2 parameter will be called
sum(10,20,30); //sum() with 3 parameter will be called
}
The output of the program is tested on www.jdoodle.com
Output:
30
60
Thanks
Mukesh Rajput
Post A Comment:
0 comments: