Professional Documents
Culture Documents
Overloading Is The Reuse of The Same Function Name or Symbol For Two or More Distinct Functions or Operations
Overloading Is The Reuse of The Same Function Name or Symbol For Two or More Distinct Functions or Operations
Advantages :-
2) It also save overhead of variables push/pop on the stack, while function calling.
5) After in-lining compiler can also apply intraprocedural optmization if specified. This is the most
important one, in this way compiler can now focus on dead code elimination, can give more stress on
branch prediction, induction variable elimination etc..
"Overloading is the reuse of the same function name or symbol for two or more distinct functions or
operations"
Function overloading is the general concept of c++. A function can be declared more than once with
different operations. Function overloading means two or more functions can have the same name but
either the number of arguments or the data type of arguments has to be different. Return type has no
role because function will return a value when it is called and at compile time compiler will not be able
to determine which function to call. In the first example in our code we make two functions one for
adding two integers and other for adding two floats but they have same name and in the second
program we make two functions with identical names but pass them different number of arguments.
Function overloading is also known as compile time polymorphism.
#include <iostream>
void display(char []); // print the string passed as argument
int main()
display(first);
display(first, second);
return 0;
Output of program:
C programming
C programming
C++ programming
#include <iostream>
using namespace std;
int main()
1. {
2. int a, b, c, m;
cout << "Enter the values of a, b and c: ";
3. cin >> a >> b >> c;
4. m = (b * b) - (4 * a * c);
5. if (m >= 0)
6. {
7. cout << "Roots are real" << endl;
8. }
9. else
10. {
11. cout << "Roots are imaginary" << endl;
12. }
13. return 0;