+ 1

What is function overloading?

2nd Apr 2018, 9:13 AM
Saifullah Rahman
Saifullah Rahman - avatar
3 Answers
2nd Apr 2018, 9:18 AM
Memphis Reigns
Memphis Reigns - avatar
+ 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.
2nd Apr 2018, 9:54 AM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
2nd Apr 2018, 9:17 AM
Aaron Eberhardt
Aaron Eberhardt - avatar