Function Prototype & Function Overloading

Function Prototype:

Function prototype also referred to as function signature specifies the number of arguments and return type of the function to the compiler. Function prototype is required when a function is invoked/called before it is defined. The following statement defines function prototype.

            <Return type> function_name(arguments);

where return type is any valid C++ data type. The arguments are the parameters or values passed to the function when it is invoked. The argument variable names in prototype are optional.

Function Overloading:

Function overloading refers to defining different functions with the same name but with different arguments and return types. This is also referred to as functional polymorphism, as overloading is a form of polymorphism. This function to be invoked is determined by the type and number of arguments passed to that function.

For example: if we have to find the sum of two numbers of type int as well as float type we need not define two different functions with different names.  Now we can define both the functions bearing same name but different argument type.

int add (int a, int b);

float add(float a, float b);

Now the same function ‘add’ sums up two integer values and returns an integer as well as float values, thereby returning float value.