Write a Program to demonstrate Function Overloading

/*
    Program to demonstrate Function Overloading
*/
#include<iostream>
using namespace std;

int sum(int,int,float);
float sum(float,float);
int sum(int,int,int);

int main()
{
    int a=10,b=10,c=10,s;

    s=sum(a,b);
    cout<<"\n\n Sum: "<<s;


    s=sum(a,b,c);
    cout<<"\n\n Sum: "<<s;

    return 0;
}

int sum(int a,int b)
{
    return a+b;
}

float sum(float a,float b)
{
    return a+b;
}
int sum(int a,int b,int c)
{
    return a+b+c;
}

Previous
Next Post »