Function Overloading in C++ Programming

#include<iostream>
using namespace std;
void add(int,int);
void add(int,int,int);
int main()
{
    add(2,5);
    add(2,3,4);
    return 0;
}
void add(int x,int y)
{
    int z;
    z=x+y;
    cout<<"sum of the number="<<z<<endl;
}

void add(int a,int b,int c)
{
    int d;
    d=a+b+c;
    cout<< "sum of the number="<<d;
}
OUTPUT:
Here we have same function name 'add' but with different parameter so the function are overloaded.

No comments

Powered by Blogger.