Wednesday, May 28, 2014

Function overloading

Posted by Unknown On 6:35 AM No comments

Function overloading -  it is a feature of c++ that allows us to create multiple functions(many functions) under the same name but the only thing is that they want to have different parameters



#include<iostream>
using namespace std;
void print (int x)
{
cout<<"the integer no is"<<x;
}
void print (float x)
{
cout<<" the float number is "<<x;
}
int main()
{
int a;
float b;
a=45;
b=5.55;
print(a);
print(b);
return 0;
}

here we are using the same function name for the 2 different functions. but the parameter of the 1st function is the type int  .  the parameter of the 2nd function is foat. .
so when we return a value from the main it checks its integer type and passes it to the desired function which is having the same parameter