Function-Overloading in c++ .

In this session i have discussed function overloading in C++ .


The function overloading is the new feature in C++ . In function overloading there are many method with same name but their parameters (arguments) are different .


Example : Write a program that demonstrate the function overloading .

  #include<iostream>
  using namespace std; 
  int sum(int x,int y)
  {
        return(x+y);
  }
  int sum(int x,int y , int z)
  {
        return(x+y+z);
  }
  int main()
  {  
       int x,y,z;
       x=20;
       y=10;
       z=30;
       cout<<"\nSum function with two arguments  ";
       cout<<"\nSum :  "<<sum(x,y);
       cout<<"\nSum function with three arguments  ";
       cout<<"\nSum :  "<<sum(x,y,z);
       return 0;
  }
  
  
  OUTPUT : Sum function with two arguments
           Sum : 30
           Sum function with three arguments
           Sum : 60
    


Welcome to AndroidATPoint.

back image                     next image