Function Overloading

Function Overloading allows a same named function to be used, that will act differently depending upon how it is invoked. Specifically, it depends upon the data type, number and order of arguments in the parameter list.

 

For instance, say you wanted to add two numbers but had different data types; integers and floats. If a single function was used accepting integers as its formal parameters, any precision required for floating point numbers would be lost.

 

Therefore, another similar function can be created that accepts floats, to keep the precision:

Compile & Run:

17 + 42 = 59
1.234 + 5.678 = 6.912

Leave a Reply