Functions differ in number of parameters : Function Overloaded « Function « C++






Functions differ in number of parameters

Functions differ in number of parameters
 

#include <iostream>
using namespace std;

int myFunction(int i);       
int myFunction(int i, int j);

int main()
{
  cout << myFunction(10) << " "; // calls myFunction(int i)
  cout << myFunction(4, 5);      // calls myFunction(int i, int j)

  return 0;
}

int myFunction(int i)
{
  return i;
}

int myFunction(int i, int j)
{
  return i*j;
}


           
         
  








Related examples in the same category

1.Overload abs() three waysOverload abs() three ways
2.Overload function: int and longOverload function: int and long
3.Create three functions called prompt( ) that perform this task for data of types int, double, and long
4.Overload function to accept integer or char * argumentOverload function to accept integer or char * argument
5.Overload the min() function.Overload the min() function.
6.Compute area of a rectangle using overloaded functions.Compute area of a rectangle using overloaded functions.
7.Overload function: int and floatOverload function: int and float
8.function overloading between int and string type