what do you mean by function overloading
Answers
Definition:-
Function overloading is a feature in C++ where two or more functions can have the same name but different parameters.
Function overloading can be considered as an example of polymorphism feature in C++.
Following is a simple C++ example to demonstrate function overloading.
#include <iostream>
using namespace std;
void print(int i) {
cout << " Here is int " << i << endl;
}
void print(double f) {
cout << " Here is float " << f << endl;
}
void print(char* c) {
cout << " Here is char* " << c << endl;
}
int main() {
print(10);
print(10.10);
print("ten");
return 0;
}
Output:
Here is int 10
Here is float 10.1
Here is char* ten
Answer:
C++ allows you to specify more than one function of the same name in the same scope. . Overloaded functions allow you to supply different semantics for a function depending on the types and number of its arguments
When a function name is overloaded by different tasks, it is called function overloading. In function overloading, the function name should be the same and the arguments should be different. Function overloading can be considered as an example of polymorphism property in C++.
Function overloading in c++ is used to improve code readability. It is used so that the programmer does not have to remember different function names. If a class has multiple functions with different parameters with the same name, they are said to be overloaded. If we need to perform a single operation with different numbers or types of arguments, we need to overload the function.
#SPJ5