+ 1
What is function overloading?
3 Answers
+ 1
In any programming language, there is a need to write different functions with same name but accept different types and number of parameters.
A simple example could be abs() function which return the absolute value of the given parameter regardless of the type (int, float, double)
abs(-123)
abs(42.6)
So you write two functions like the following
int abs(int x) {
return (x < 0)? -x: x;
}
float abs(float x) {
return (x < 0)? -x: x;
}
so the abs function here is said to have been overloaded.
There are better ways to write the above two functions, I have given them only for illustration purposes.