FUNCTION OVERLOADING
It will be more clear with the help of the program.
PROGRAM:
#include<iostream.h>#includ<conio.h>
void show(int a) //Function 1
{
cout<<"This function contains Integer value = "<<a;
}
void show(float b) //Function 2
{
cout<<"This function contains Float value = "<<b;
}
void main()
{
clrscr();
// Now we will Call the functions
show(2.3);
show(10);
getch();
}
OUTPUT:
This function contains Float value = 2.3This function contains Integer value = 10
Now the first calling was 'show(2.3)'. This was a float value, so the compiler compared both the functions and their Return types and Parameters. When it found the float value, the function 2 was called then. Then the next call 'show(10)' was having an Integer value, so comparing with the parameters it executed the First Function.
Also :