Function Overloading in C
Here are the implementation of the function overloading in c language:
#include <stdio.h>
void add_int(int a, int b) {
printf("sum = %d\n", a + b);
}
void add_double(double a, double b) {
printf("sum = %f\n", a + b);
}
int main() {
add_int(10, 2);
add_double(5.3, 6.2);
return 0;
}
Output
sum = 12 sum = 11.500000
Function Overloading in Programming
Function Overloading in programming allows multiple functions to have the same name but with different parameters. It lets a function perform different tasks based on the input parameters. This increases the flexibility and readability of the code. Languages like C++, Java, and C# have function overloading. A programmer can provide different implementations for one function name. The number and types of parameters differentiate them. This enhances code readability and usability. Conceptually similar tasks are handled by function variants.
Table of Content
- What is Function Overloading?
- How Function Overloading Works?
- Implementation of Function Overloading
- Constructors and Destructors Overloading
- Constructor Overloading
- Destructor Overloading:
- Operator Overloading:
- Function Overloading in C
- Function Overloading in C++
- Function Overloading in Java
- Function Overloading in Python
- Advantages of Function Overloading
- Disadvantages of Function Overloading
- Use cases of Function Overloading